WP e-Commerce and GoldCart replace $0.00 prices with message.
The question
I’ve been searching for some code so that if the price is £0.00, then a piece of text along the lines of ‘Price on application’ is pulled through.
I have found this post on your site and attempted to make it work. I think the different plugin versions mean that I can’t get it right.
I am using WP eCommerce Version 3.8.9.5
and Gold Cart Version 2.9.7.3
Answer
This answer assumes you have a theme which uses the default template files from the WP e-Commerce plugin. This is quite common. (If you have a theme which includes custom versions of these files you will have to attempt to apply this code to your theme.)
Depending on your setup there are 4 PHP files you may need to edit. If you have never edited PHP see the Tools panel at the end of this post and jump in. The four files are
- wpsc-products_page.php
- wpsc-single_product.php
- wpsc-list_view.php
- wpsc-grid_view.php
If you are NOT using the Gold Cart plugin you should alter the first two. If you are using Gold Cart you will want to alter 2 and either 3 or 4 depending on which view you have set in WP e-Commerce on Settings/Store/Presentation tab for “Product Display:”
I recommend just altering all four actually. That way if you decide to change your settings later it will just work and you will not have to remember where you found this code! You can of course replace the message “Price on application” in the code below with any message you desire.
First copy the files
In the WordPress backend go to Settings/Store/Presentation tab, in the advanced settings panel in the list of files check the four from the list above. If you do not have Gold Cart you will only see 1 and 2. Then click the ‘Move Template Files” button. This will copy the four files to your theme folder. You can modify them there. The modified ones from your theme folder will load, over-riding the ones from WP e-Commerce. This means you can update the plugin without over-writing your changes.
Code file 1
I am going to add big chunks of code here on the first example to help you understand what you are looking for. After that I will make the code examples shorter. Open wpsc-single_product.php from your theme folder. Find the highlighted line around line 140.
<div class="wpsc_product_price"> <?php if(wpsc_show_stock_availability()): ?> <?php if(wpsc_product_has_stock()) : ?> <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div> <?php else: ?> <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div> <?php endif; ?> <?php endif; ?> <?php if(wpsc_product_is_donation()) : ?> <label for="donation_price_<?php echo wpsc_the_product_id(); ?>"><?php _e('Donation', 'wpsc'); ?>: </label> <input type="text" id="donation_price_<?php echo wpsc_the_product_id(); ?>" name="donation_price" value="<?php echo wpsc_calculate_price(wpsc_the_product_id()); ?>" size="6" /> <?php else : ?> <?php wpsc_the_product_price_display(); ?> <!-- multi currency code --> <?php if(wpsc_product_has_multicurrency()) : ?> <?php echo wpsc_display_product_multicurrency(); ?> <?php endif; ?> <?php if(wpsc_show_pnp()) : ?> <p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p> <?php endif; ?> <?php endif; ?> </div><!--close wpsc_product_price-->
Replace that line with the code highlighted below
<div class="wpsc_product_price"> <?php if(wpsc_show_stock_availability()): ?> <?php if(wpsc_product_has_stock()) : ?> <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div> <?php else: ?> <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div> <?php endif; ?> <?php endif; ?> <?php if(wpsc_product_is_donation()) : ?> <label for="donation_price_<?php echo wpsc_the_product_id(); ?>"><?php _e('Donation', 'wpsc'); ?>: </label> <input type="text" id="donation_price_<?php echo wpsc_the_product_id(); ?>" name="donation_price" value="<?php echo wpsc_calculate_price(wpsc_the_product_id()); ?>" size="6" /> <?php else : ?> <?php if (wpsc_the_product_price() != '$0.00'){ wpsc_the_product_price_display(); } else { _e('Price on application', 'wpsc'); }?> <!-- multi currency code --> <?php if(wpsc_product_has_multicurrency()) : ?> <?php echo wpsc_display_product_multicurrency(); ?> <?php endif; ?> <?php if(wpsc_show_pnp()) : ?> <p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p> <?php endif; ?> <?php endif; ?> </div><!--close wpsc_product_price-->
Watch out, if not using $ as your currency, remember to change that in the code
If you do not the code will not detect a match. For example $0.00 will not match £0.00 and the price will not be removed.
Code file 2
For the products page when not using Gold Cart you need to edit wpsc-products_page.php. Find the highlighted line around 172.
<?php else : ?> <?php wpsc_the_product_price_display(); ?>
Replace that line 172 with the code below
<?php else : ?> <?php if (wpsc_the_product_price() != '$0.00'){ wpsc_the_product_price_display(); } else { _e('Price on application', 'wpsc'); }?>
Code file 3
When using Gold Cart for the list view you need to edit wpsc-list_view.php. Find the highlighted line around 92.
<td class='wpsc_price_td'> <?php wpsc_the_product_price_display( array( 'output_you_save' => false ) ); ?> </td>
Replace line 92 with the highlighted code below
<td class='wpsc_price_td'> <?php if (wpsc_the_product_price() != '$0.00'){ wpsc_the_product_price_display(); } else { _e('Price on application', 'wpsc'); }?> </td>
Code file 4
When using Gold Cart for the grid view you need to edit wpsc-grid_view.php. Find the highlighted line around 88.
<div class="price_container"> <?php wpsc_the_product_price_display( array( 'output_you_save' => false ) ); ?> </td>
Replace line 88 with the highlighted code below
<div class="price_container"> <?php if (wpsc_the_product_price() != '$0.00'){ wpsc_the_product_price_display( array( 'output_you_save' => false ) ); } else { _e('Price on application', 'wpsc'); }?>
What if it needs to be a link?
If for instance this is used as ‘Price on application’ like in the code and your site has a contact form, why not have the text link to that page? You will need something like below. Change the URL to match that of the contact page on your site. This is the basic concept, each of the examples above varies slightly. You can work it out. I can’t do all of the work for you. basically in all 4 bits of the code I provide above
You replace this
else { _e('Price on application', 'wpsc'); }?>
with this
else { ?> <p class = "pricedisplay wpsc-product-price"> <span class = "currentprice pricedisplay"> <a class="poa" href="http://mysite/contact/"><?php _e('Price on application', 'wpsc'); ?></a></span> </p> <?php }?>
Some CSS
I am using the same classes as WP e-Commerce so most formatting will match. You then have a new class ‘poa’ on the link. You can use this to style it. For example make it red and add some space above and below.
.poa{ color:#ff0000; line-height:2em; }
Tools:
You may edit your PHP outside WordPress and upload it to your server. You must use an appropriate code editor NOT microsoft word or anything like that which adds a lot of invisible formatting and will be a disaster.
If you do not have one, 2 excellent free ones are…
TextWrangler for Mac, http://www.barebones.com/products/textwrangler/
Notepad++ for the PC http://notepad-plus-plus.org/
2 Comments
Foster
December 14, 2015This was originally deepeolvd for Studiopress themes (Genesis) and for Genesis child themes you simply have to activate the plugin and it will work. To make it work on non-Genesis themes, please follow these instructions to update your theme hide WordPress author and date on non-Genesis themes.
Sv
January 14, 2015Hi! i’m from Argentine. Sorry for my Fool English
I bouht The Lookshop Theme that include WpEcommerce
I need HIDE the product Prices in all template.
May be can I replace 0,00 $ for a text, for example “Call Now”
In the individual product I succeeded, but on the grid of products, still appears 0,00 under each product. Can you help me please? THANKS A LOT!!!
Jorge