Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<span class="price">
<del><span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">&euro;</span>65.00
</span></del>
<ins><span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">&euro;</span>55.00
</span></ins>
</span>
<?php
/*
Plugin Name: Show Sale Price and RRP - per product or category
Plugin URI: https://www.damiencarbery.com/2018/04/woocommerce-display-only-sale-price/
Description: Display discounted or sale price with the RRP under it. Limit to specified products and categories.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.2
*/
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
// Display regular price when viewing these products or categories.
$products = array( 27, 28 );
$categories = array( 'accessories', 'hoodies' );
$show_regular_price = false;
// Include products in a category archive and in related products section.
$product_id = get_the_ID();
if ( in_array( $product_id, $products ) ) {
$show_regular_price = true;
}
// Check whether current category is in the list.
if ( is_product_category() ) {
$queried_object = get_queried_object();
$category_slug = $queried_object->slug;
if ( in_array( $category_slug, $categories ) ) {
$show_regular_price = true;
}
}
if ( $show_regular_price ) {
return sprintf( '<span class="sale_price">%s</span> <span class="rrp">RRP: %s</span>',
wc_price( $sale_price ), wc_price( $regular_price ) );
}
else {
return $price;
}
}
<?php
/*
Plugin Name: Show Sale Price and RRP
Plugin URI: https://www.damiencarbery.com/2018/04/woocommerce-display-only-sale-price/
Description: Display discounted or sale price with the RRP under it.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
return sprintf( '<span class="sale_price">%s</span> <span class="rrp">RRP: %s</span>',
wc_price( $sale_price ), wc_price( $regular_price ) );
}
<span class="price">
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">&euro;</span>55.00
</span>
</span>
<?php
/*
Plugin Name: Show Only Sale Price
Plugin URI: https://www.damiencarbery.com/2018/04/woocommerce-display-only-sale-price/
Description: Display only the reduced price when a product is discounted or on sale.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
return wc_price( $sale_price );
}
@tremblayly

This comment has been minimized.

Copy link

commented Jun 20, 2019

Can the display both prices in the cart and at checkout pages be adapted to displaying the wholesale price based on wholesale user role?

@damiencarbery

This comment has been minimized.

Copy link
Owner Author

commented Jun 21, 2019

Can the display both prices in the cart and at checkout pages be adapted to displaying the wholesale price based on wholesale user role?

Probably (I don't 100% understand your question but I am sure that displaying the full and wholesale prices could be displayed in the cart and checkout).

In the dcwd_sale_price() function you would need to add extra checks e.g. that the user is logged in and find their role.
Are you using a plugin to set the wholesale price and the wholesale user role? How many different wholesale user roles do you have?
What price is currently being displayed? Full or wholesale?

@tremblayly

This comment has been minimized.

Copy link

commented Jun 21, 2019

I use the Wholesale Suite of plugins - Wholesale Premium Prices which allows me to create the roles and enter pricing for each of them within when creating a product. I have 15 wholesale roles because of tax exemptions (in Canada we have two taxes (GST & PST) and some customers can exempted from paying one only or none):
// charge both PST and GST $map['wholesale_customer'] = 'WholesalePSTGST'; $map['ws_silvia_silver'] = 'WholesalePSTGST'; $map['ws_silvia_gold'] = 'WholesalePSTGST'; $map['ws_silvia_premium'] = 'WholesalePSTGST'; $map['ws_silvia_union'] = 'WholesalePSTGST'; // charge only GST $map['wholesale_pst_exempt'] = 'WholesalePSTExempt'; $map['ws_silvia_silver_pst_exempt'] = 'WholesalePSTExempt'; $map['ws_silvia_gold_pst_exempt'] = 'WholesalePSTExempt'; $map['ws_silvia_premium_pst_exempt'] = 'WholesalePSTExempt'; $map['ws_silvia_union_pst_exempt'] = 'WholesalePSTExempt'; // charge neither $map['wholesale_tax_exempt'] = 'WholesaleZeroTax'; $map['ws_silvia_silver_tax_exempt'] = 'WholesaleZeroTax'; $map['ws_silvia_gold_tax_exempt'] = 'WholesaleZeroTax'; $map['ws_silvia_premium_tax_exempt'] = 'WholesaleZeroTax'; $map['ws_silvia_union_tax_exempt'] = 'WholesaleZeroTax';

The shop and single product pages, once a wholesale customer logs in, he can see the retail (with a line across) and the wholesale prices. However in the cart and checkout pages, the customer only sees the wholesale prices applied. Customers have been asking to see both prices and my client also wants both prices to show - including subtotals/totals.

@tremblayly

This comment has been minimized.

Copy link

commented Jun 21, 2019

That code snippet is for applying different tax rates to specific wholesale user roles.

@damiencarbery

This comment has been minimized.

Copy link
Owner Author

commented Jun 21, 2019

Is it this plugin? https://wholesalesuiteplugin.com/woocommerce-wholesale-prices-premium/
It's a premium plugin that I do not have access to.
You could look to find what code sets the display price in cart and checkout - it's probably an apply_filters() call that you could add_filter() to. It's impossible to give any other ideas without seeing the plugin code.

As the plugin is a premium one, you should ask their Support people to help you - that is part of the thing you are paying for.

@tremblayly

This comment has been minimized.

Copy link

commented Jun 21, 2019

@damiencarbery

This comment has been minimized.

Copy link
Owner Author

commented Jun 23, 2019

I didn't see any zip attached. Email me directly at damien@damiencarbery.com

@damiencarbery

This comment has been minimized.

Copy link
Owner Author

commented Jul 8, 2019

For anyone else interested int the code that I wrote for Lyse:
Show regular price in cart and checkout when using WooCommerce Wholesale Prices
https://www.damiencarbery.com/2019/07/show-regular-price-in-cart-and-checkout-when-using-woocommerce-wholesale-prices/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.