Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Hide price in one category

Hide price in one category

Views: 5,889

Results 1 to 20 of 29
12 Jul 2016, 9:05 PM
#1
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Hide price in one category

Hi, I found a very old, closed, thread about this but the coding has changed so much since then.

I need to hide the product price in one category. When my customer sells his bespoke items he wants to move them into a "sold" category so people can see his old products. I need the price to not be displayed in this category.

As far as I can see I will need to edit the product info display somewhere around the price block with conditional "else" command but I have no idea how to code it

vrs 1.5.5

Thanks in advance

Congerman

12 Jul 2016, 9:26 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Hide price in one category

What should the price display instead?

In functions_prices, in the zen_get_products_display_price() function you could make this change, which ONLY blanks-out the price. It does NOT deny add-to-cart capability etc:

    $product_check = $db->Execute("select master_categories_id, products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");

if ($product_check->fields['master_categories_id'] == 10) { // change '10' here to the category number 
  return '';
}

Edit: The product-type change idea below is probably the most efficient: once configured it's as easy as making the change to the one field in the db. There's no admin-provided tool for changing product-types assigned to products though, as there are caveats to that if one isn't changing types on like-for-like defined types.

12 Jul 2016, 9:27 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

You could with a sql statement change the product type to say document general where the price display could be independently controlled to not display for document general product.

The field in the products table is products_type and would be 3 for that product type in a default ZC install.

12 Jul 2016, 10:20 PM
#4
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

DrByte:

What should the price display instead?

In functions_prices, in the zen_get_products_display_price() function you could make this change, which ONLY blanks-out the price. It does NOT deny add-to-cart capability etc:

$product_check = $db->Execute("select master_categories_id, products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");


if ($product_check->fields['master_categories_id'] == 10) { // change '10' here to the category number
return '';
}

> 
> 
> Edit: The product-type change idea below is probably the most efficient: once configured it's as easy as making the change to the one field in the db. There's no admin-provided tool for changing product-types assigned to products though, as there are caveats to that if one isn't changing types on like-for-like defined types.

Thanks DR Byte for the idea i will try it, also is it possible to do what was in the old thread in the newer version   something like the below from the old thread?

**I managed to remove the product price when quantity was 0 or less by editing the file that Linda mentioned. Here is what I did (using ZenCart 1.3.8a):
Copied the file catalog/includes/templates/tpl_product_info_display.php into my
catalog/includes/templates/OVER_RIDE_DIR/templates/ directory.

In the file I copied, I found the Product Price Block section.
Then located the line
Code:

  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);

and replaced it with
Code:

if ($products_quantity > 0) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);
} else {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') ;
 }

**

my price block looks like this

<!--bof Product Price block -->
	<div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <?php if($specials_price): ?>
      <span class="base-price"><?= $products_base_price ?></span>
      <span class="sale-price" itemprop="price"><?= $specials_price ?></span>
    <?php else: ?>
      <span class="sale-price" itemprop="price"><?= $products_base_price ?></span>
    <?php endif; ?>
    <?php if($show_onetime_charges_description == 'true'): ?>
      <span class="one-time"><?= TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION ?></span>
    <?php endif; ?>
	</div>
12 Jul 2016, 10:32 PM
#5
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

Hi again Dr Byte

Just tried your code and it change the price to £0.00 instead of not displaying it.

12 Jul 2016, 11:26 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

You have short codes in the file:

<?= $variable

Should be rewritten as:

<?php echo $variable;

The if statements use an alternative method of construction, but I haven't seen issue with that usage any time recently (though also haven't seen that used in a long time either. :)) normally the colon (:) would be an open curly ({) and the endif; would be a closing curly (}), but whatever. :)

12 Jul 2016, 11:46 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

The other thing it would seem is that this code should only apply if the product is in the "sold" category and otherwise the normal code should apply.

There is a zen function that can help with the logic:

zen_product_in_category($products_id, $cat_id)

You provide/code the category_id and feed whatever product is being looked up/displayed. Involves a lot of database access, but solves the "auto" action.

13 Jul 2016, 8:59 AM
#8
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

Thanks for the reply, Not understanding it though.

Can someone tell me how to modify dr bytes code so instead of showing the price of £0.00 it just does not display anything in the price or just put the word sold where the price was

$product_check = $db->Execute("select master_categories_id, products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");

if ($product_check->fields['master_categories_id'] == 3) { // change '10' here to the category number
return '';
}

Thanks

13 Jul 2016, 10:00 AM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

Congerman:

Thanks DR Byte for the idea i will try it, also is it possible to do what was in the old thread in the newer version something like the below from the old thread?

**I managed to remove the product price when quantity was 0 or less by editing the file that Linda mentioned. Here is what I did (using ZenCart 1.3.8a):
Copied the file catalog/includes/templates/tpl_product_info_display.php into my
catalog/includes/templates/OVER_RIDE_DIR/templates/ directory.

In the file I copied, I found the Product Price Block section.
Then located the line
Code:

echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);

and replaced it with
Code:

if ($products_quantity > 0) {
echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);
} else {
echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') ;
}

**

my price block looks like this

<!--bof Product Price block -->
<div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if($specials_price): ?>
  <span class="base-price"><?= $products_base_price ?></span>
  <span class="sale-price" itemprop="price"><?= $specials_price ?></span>
<?php else: ?>
  <span class="sale-price" itemprop="price"><?= $products_base_price ?></span>
<?php endif; ?>
<?php if($show_onetime_charges_description == 'true'): ?>
  <span class="one-time"><?= TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION ?></span>
<?php endif; ?>
</div>

Looked at this again and I think I get it. Modify your price block section from:

<!--bof Product Price block -->
<div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if($specials_price): ?>
<span class="base-price"><?= $products_base_price ?></span>
<span class="sale-price" itemprop="price"><?= $specials_price ?></span>
<?php else: ?>
<span class="sale-price" itemprop="price"><?= $products_base_price ?></span>
<?php endif; ?>
<?php if($show_onetime_charges_description == 'true'): ?>
<span class="one-time"><?= TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION ?></span>
<?php endif; ?>
</div>
```
To:
```
<!--bof Product Price block -->
<div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php [B]if($products_quantity>0):[/B]
if($specials_price): ?>
<span class="base-price"><?= $products_base_price ?></span>
<span class="sale-price" itemprop="price"><?= $specials_price ?></span>
<?php else: ?>
<span class="sale-price" itemprop="price"><?= $products_base_price ?></span>
<?php endif; 
[B]endif;[/B]?>
<?php if($show_onetime_charges_description == 'true'): ?>
<span class="one-time"><?= TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION ?></span>
<?php endif; ?>
</div>
```

This will prevent the display of the products price if the quantity of product remaining is 0 or less. This does not discriminate based on category.
If you want to only have this apply for product in a certain category, then change ```
if($products_quantity>0):

To:

if(!zen_product_in_category((int)$_GET['products_id'], 10)):

Where 10 should be changed to the category number of the sold category. Thus, product that do reach a 0 quantity while in another category will still reflect the price that existed, until the product is added to the "sold" category.

Problem that might exist with this is that the itemprop data will be missing for the price which might present an issue with the applicable price review "engine". Ie. May be considered incorrect data for the product. I'm not familiar with the requirements to say that it will be, just that it won't be presented.

13 Jul 2016, 1:22 PM
#10
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

That is great, Thank you. I went down the category code route.

Now one other problem. The price still shows on the listing page for that category. Cannot seem to find the listings page template and what code do I need for the listings template?

13 Jul 2016, 3:24 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Hide price in one category

Congerman:

Now one other problem. The price still shows on the listing page for that category. Cannot seem to find the listings page template and what code do I need for the listings template?
This is why the product-type approach is better.

13 Jul 2016, 5:40 PM
#12
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

Thanks dr Byte

How do I get your code to display no price rather than £0.00

$product_check = $db->Execute("select master_categories_id, products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");

if ($product_check->fields['master_categories_id'] == 10) { // change '10' here to the category number
return '';
}

13 Jul 2016, 6:11 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Hide price in one category

Congerman:

Thanks dr Byte

How do I get your code to display no price rather than £0.00

$product_check = $db->Execute("select master_categories_id, products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");

if ($product_check->fields['master_categories_id'] == 10) { // change '10' here to the category number
return '';
}
When I tested it it displayed no price at all. But I only use USD on my sites. Perhaps you've got something reformatting the price again and that is treating the "blank response" as "0" and then reformatting that to £0.00 ?

13 Jul 2016, 6:58 PM
#14
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

Thanks for comming back. GBP is the only currency in my admin, and surely currency only changes the symbel and exchange rate can you look at artofrecycling.co.uk/shop and then the sold category. Could really do with hiding the £0.00

Could you advise a code, maybe css to display no price field if that category?

thanks for the help so far Dr Byte

14 Jul 2016, 12:10 PM
#15
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

DrByte:

When I tested it it displayed no price at all. But I only use USD on my sites. Perhaps you've got something reformatting the price again and that is treating the "blank response" as "0" and then reformatting that to £0.00 ?

Hi could your code be adapted to show an image instead of price on that category?

14 Jul 2016, 1:10 PM
#16
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

Congerman:

Hi could your code be adapted to show an image instead of price on that category?
I think really the issue is can your code be modified to adapt to the data provided by DrByte's suggested modification? Okay, not so much can it be modified, but what is different that is causing this issue? Ie. How is the code on your site different than a vanilla install of ZC? (file/folder comparison software is available either as a free or commercial product.) Already the template code is different as described by the use of short codes, there is likely something else that is different causing the observed issue.

14 Jul 2016, 5:44 PM
#17
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

I find it great that I am getting all the insights about template coding, and I am appreciative. I am not a coder. I am using the BANA template. I would love for someone who knows that template to be able to assist in hiding the price field in category 3 listing page.

As a fix all I will have to use css to not display prices on all category listings pages, but my client would prefer not to go down that route.

Thanks to all so far for your imput in trying to resolve this for me

14 Jul 2016, 6:05 PM
#18
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

If they are OK with just the applicable category not showing prices (provided product is not a new, special or featured product) then you could create a css file just for that category. See the readme/info file in includes/templates/template_default/css

14 Jul 2016, 6:17 PM
#19
congerman avatar

congerman

Zen Follower

Join Date:
Oct 2008
Posts:
392
Plugin Contributions:
0

Re: Hide price in one category

in all the years I have been using zen cart I have never noticed that file

So c_??_??.css would apply changes only to one category? Is the first ?? the category number and the second ?? the product number within that category?

would I just create a css file called c_03.css and then just display none the price field and it will only affect category 3?

A fantastic find if it is that simple

I would have to set no products to be marked as new as well I guess

14 Jul 2016, 7:03 PM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Hide price in one category

Congerman:

in all the years I have been using zen cart I have never noticed that file

So c_??_??.css would apply changes only to one category? Is the first ?? the category number and the second ?? the product number within that category?

would I just create a css file called c_03.css and then just display none the price field and it will only affect category 3?

A fantastic find if it is that simple

I would have to set no products to be marked as new as well I guess
Well, there is one thing though, the price won't be seen by the vast majority of customers, but the price data will still be present (view source will still show whatever price and search engines basically ignore css).

Otherwise, regarding the category css files, they are perhaps/possibly the most finicky because a category can be shown as the base/master category, but it can be a sub-sub-etc category and therefore the cPath could include just the finally category or sub-categories before it. But yes, effectively a single file could be used to visually hide something related to a particular category.

Solutions such as these tend to get offered when the goal is clearly identified and understood. Again to clearly state, using css to visually hide the price will still cause the product's price to be found in an Internet search only for a customer to arrive at a page indicating that the product was sold. It is not much of a plus to the customer's shopping experience... but then again, the store is being operated to keep the product listed, but under a sold category...