WP e-Commerce, make $0.00 items show “Please request a quote” message

The question

Is there an option to hide the prices (as it doesn’t really apply) on some products? or is there a way to use this solution: http://getshopped.org/forums/reply/reply-to-how-to-hide-the-price-if-zero-7/ in the Elegance theme? Can it link to a contact/enquiry form.

Answer

Well hiding a price on a per product basis is possible with CSS but the linked solution is much nicer. So the code below which is basically a minor update for newer WP e-Commerce versions will, if you leave the price of the product at 0.00, display “This product requires an individual quote” bolded in red. You can change the message as you see fit. You could also leave the message empty and this would just remove the price. Thanks to the anonymous getShopped poster for the head start. For the link to a contact form we can use a built in WP e-Commerce feature so that we have a nice button that matches the site.

So first you need a contact page. There are many options. I use Gravity Forms but it is a fairly expensive and very powerful plugin. I highly recommend it for forms but if you just want a contact form it is over kill. If you just want a contact form I recommend Contact Form 7. It is simple and has been around a long time, which means there is a whole world of handy add-ons for it. These can also be found circulating for free in the WordPress plugins page. One I strongly suggest you implement is Contact Form 7 Honeypot. This is a spam prevention add on that does not require your users to fill in those very very annoying Captcha things!

So your contact form is made and installed on a page, very creatively called ‘Contact’. Now go to the ‘Offsite Product Link” panel on the edit page for your Product. If you can not see it, click the Screen Options tab in the top right corner of the screen. When it slides open, check the box to display the ‘Offsite Product Link’. Using this will have the added benefit of removing the ‘Add To Cart’ button.

  1. In the ‘External Link’ field enter the URL of your contact form.
  2. In the ‘External Link Text’ field enter the text you would like to appear on the button that links to your contact form.
  3. For ‘External Link Target’ I suggest choosing ‘Open link in a new window’ This way the user still has the Product page open to refer to when writing their enquiry.

So now you have a button, time to add some code to deal with the price.

Code

Open wpsc-single_product.php which is in the Elegance folder (or the folder of any theme you are using). Find this line around line 181 in Elegance 1.4.5. In other versions even other themes you should be able to locate this, even if it is not exactly the same. This code is a bit updated from the version in the link. If you have never edited PHP see the Tools panel at the end of this post and jump in.
If you have a different theme look for echo wpsc_the_product_price in the same file.

<?php echo __('Price', 'wpsc'); ?>: <span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="pricedisplay"><?php echo wpsc_the_product_price(); ?></span><br/>

Replace that line with the code below

<?php if (wpsc_the_product_price() == "$0.00") : ?>
	<span class="special"><?php echo "This product requires an individual quote"?></span>
<?php else : ?>
	<?php echo __('Price', 'wpsc'); ?>: <span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="pricedisplay"><?php echo wpsc_the_product_price(); ?></span><br/>
<?php endif; ?>

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.

Update

Thanks to Storefront user Raegan Reed for taking the time to figure out, document and post the changes needed to do this on the Products Page and Category pages as well. You need to edit wpsc-products_page.php
In Elegance 1.4.5 you should see it around line 200.

<?php if ( get_option('storefront_gridview_price') == "true" && get_option('storefront_gridview') == "true" ) {echo "<div class='sft-gridview-price'><span class='sft-gridview-price-text'>".wpsc_the_product_price()."</span></div>";} ?>

Replace that line with the code below

<?php if ( get_option('storefront_gridview_price') == "true" && get_option('storefront_gridview') == "true" ) { ?>
<?php if (wpsc_the_product_price() == "$0.00") : ?>
<div class='sft-gridview-price requires-quote'><span class='sft-gridview-price-text'>
<?php echo "Custom quote"?></span></div>
<?php else : ?>
<div class='sft-gridview-price'><span class='sft-gridview-price-text'>
<?php echo wpsc_the_product_price(); ?></span></div>
<?php endif; ?>
<?php } ?>

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/

1 Comment

  1. Daniel Tomalin
    September 12, 2014

    Hi

    i am trying to do this on my website but cant find the file that i need to change with the line of code in.

    I am running the lastest version of wordpress + wp-ecommerce can you help please

    Reply

Leave a Reply