Page 1 of 3 123 LastLast
Results 1 to 10 of 29
  1. #1
    Join Date
    Oct 2008
    Posts
    378
    Plugin Contributions
    0

    Default 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
    Last edited by Congerman; 12 Jul 2016 at 10:11 PM.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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:

    Code:
        $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.
    Last edited by DrByte; 12 Jul 2016 at 10:34 PM. Reason: product-type comment
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default 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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Oct 2008
    Posts
    378
    Plugin Contributions
    0

    Default Re: Hide price in one category

    Quote Originally Posted by DrByte View Post
    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:

    Code:
        $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>

  5. #5
    Join Date
    Oct 2008
    Posts
    378
    Plugin Contributions
    0

    Default 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.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Hide price in one category

    You have short codes in the file:
    Code:
    <?= $variable
    Should be rewritten as:
    Code:
    <?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. :)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default 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:

    Code:
    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Oct 2008
    Posts
    378
    Plugin Contributions
    0

    Default 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

  9. #9
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Hide price in one category

    Quote Originally Posted by Congerman View Post
    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:
    Code:
    <!--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:
    Code:
    <!--bof Product Price block -->
    <div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <?php if($products_quantity>0):
    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; 
    endif;?>
    <?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
    Code:
    if($products_quantity>0):
    To:
    Code:
    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.
    Last edited by mc12345678; 13 Jul 2016 at 11:03 AM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Oct 2008
    Posts
    378
    Plugin Contributions
    0

    Default 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?

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. v151 Hide one category from category side box
    By robbie269 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 18 Feb 2014, 03:35 PM
  2. Hide one category in LH box
    By gprit in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 26 Jul 2010, 01:49 PM
  3. Hide category count -- on only ONE category
    By reneep in forum Setting Up Categories, Products, Attributes
    Replies: 31
    Last Post: 28 Apr 2010, 08:13 PM
  4. Hide Price for only one category
    By microinfo in forum General Questions
    Replies: 2
    Last Post: 26 Jun 2008, 11:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR