Page 1 of 1
What is the correct way to hide products price?
Posted: Sat Apr 01, 2023 5:16 pm
by tessthepup
Ok so having a saturday blonde moment.
What is the correct way to hide products price on the product info page if the product has a price of 0.00?
I have tried (shortened example to keep it simple)
<?php if ($products_price == '0' ) {
echo PI_TEXT_PRODUCT_BEING_UPDATED;
}else{
<show products price code>
?>
Saying of the day 'Its the little things that make the brain hurt the most'
Thanks
Mark
Re: What is the correct way to hide products price?
Posted: Sat Apr 01, 2023 5:26 pm
by ecartz
Assuming that you are using the content module to show the price:
https://github.com/CE-PhoenixCart/Phoen ... p#L24..L29
Change that block of code to look like
Code: Select all
if ($product->get('price') == '0' ) {
$price = PI_TEXT_PRODUCT_BEING_UPDATED;
}else{
$price = $product->get('is_special')
? sprintf(MODULE_CONTENT_PI_PRICE_DISPLAY_SPECIAL,
$product->format(),
$product->format('price'))
: sprintf(MODULE_CONTENT_PI_PRICE_DISPLAY,
$product->format());
}
All the normal comments apply. E.g. it is more robust to copy the module and edit the copy than to modify the core module. Make sure that the text constant is defined before you attempt to use it. Etc.
Re: What is the correct way to hide products price?
Posted: Sun Apr 02, 2023 10:45 am
by tessthepup
@ecartz
Hi Matt,
The code I am trying to hide
https://olivias-gifts.co.uk/500ml-pure- ... -2506.html
Code: Select all
<?php
if ($product->get('price') == '0' ) {
$price = PI_TEXT_PRODUCT_BEING_UPDATED;
}else{
?>
<div class="d-flex justify-content-start border">
<div class="pt-1"><?php echo 'Qty: </span>'; ?></div>
<div class="ml-2"><?php echo (new Input('qty', ['min' => '1', 'class' => 'form-control col-4', 'id' => 'pi-qty-input'], 'number'))->default_value('1'); ?></div>
<div class="btn-buy rounded"><?php echo tep_draw_button((tep_not_null($specials_price)) ? sprintf(PI_CONTENT_PI_PRICE_DISPLAY_SPECIAL, $specials_price, '' . $products_price) : sprintf(PI_CONTENT_PI_PRICE_DISPLAY, '' . $products_price), '', null, 'primary', array('params' => 'data-has-attributes="' . (($products_attributes['total'] > 0) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['products_quantity'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-success btn-product-info btn-buy'); ?></div>
<div><?php echo tep_draw_hidden_field('products_id', (int)$product_info['products_id']); ?></div>
</div>
<?php } ?>
but I get this error
PHP Fatal error: Uncaught Error: Call to a member function get() on null
Ignore the deprecated functions as I am working on them.
Also any ideas on why I can not seem to get the button to align perfectly to the right of the input field. I have tried all sorts of different ways and it does not move urgh
Re: What is the correct way to hide products price?
Posted: Sun Apr 02, 2023 3:15 pm
by ecartz
Try going back to your original code and change to
Code: Select all
<?php if ('0' == $product_info['products_price'] ) {
echo PI_TEXT_PRODUCT_BEING_UPDATED;
}else{
<show products price code>
?>
I'm not going to be able to give more help, as I don't really recall exactly how things worked in older versions.
Re: What is the correct way to hide products price?
Posted: Sun Apr 02, 2023 4:43 pm
by tessthepup
ecartz wrote: ↑Sun Apr 02, 2023 3:15 pm
Try going back to your original code and change to
Code: Select all
<?php if ('0' == $product_info['products_price'] ) {
echo PI_TEXT_PRODUCT_BEING_UPDATED;
}else{
<show products price code>
?>
I'm not going to be able to give more help, as I don't really recall exactly how things worked in older versions.
@ecartz
Thanks Matt, a great help as usual
Re: What is the correct way to hide products price?
Posted: Mon Apr 03, 2023 2:49 pm
by burt
Don't forget that the price shows elsewhere (boxes and content modules). The simplest way to find them all is to run a search for "is-product" as this will find all the places where a product shows.
You can then override the files appropriately; if on a fairly up-to-date version of Phoenix a lot of them would be covered by /templates/{your template}/includes/components/product_card.php
Re: What is the correct way to hide products price?
Posted: Mon Apr 03, 2023 5:52 pm
by tessthepup
burt wrote: ↑Mon Apr 03, 2023 2:49 pm
Don't forget that the price shows elsewhere (boxes and content modules). The simplest way to find them all is to run a search for "is-product" as this will find all the places where a product shows.
You can then override the files appropriately; if on a fairly up-to-date version of Phoenix a lot of them would be covered by /templates/{your template}/includes/components/product_card.php
@burt
Thanks Gary, I am on the latest version and the product card was next on the list
