What is the correct way to hide products price?

Open to all! Ask other shopowners for help.
Post Reply
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

What is the correct way to hide products price?

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: What is the correct way to hide products price?

Post 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.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: What is the correct way to hide products price?

Post 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
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: What is the correct way to hide products price?

Post 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.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: What is the correct way to hide products price?

Post 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
User avatar
burt
Core Team
Posts: 4560
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 413 times

Re: What is the correct way to hide products price?

Post 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
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: What is the correct way to hide products price?

Post 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 ;)


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply