Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ideadude/f4f26e6266c2a694197003c5b36422c2 to your computer and use it in GitHub Desktop.
Save ideadude/f4f26e6266c2a694197003c5b36422c2 to your computer and use it in GitHub Desktop.
Consider member prices a "sale" so regular price is shown with a strikethrough with WooCommerce and PMPro WooCommerce
/**
* Consider member prices a "sale" so regular price is shown with a strikethrough
* If PMPro WooCommerce is active and setup to discount prices,
* then the calls to $product->get_price() will be filtered to return
* the member price.
*
* Add this code to a custom plugin.
*/
function my_pmprowoo_woocommerce_product_is_on_sale( $on_sale, $product ) {
$regular_price = (float) $product->get_regular_price();
$member_price = (float) $product->get_price();
if( $regular_price > $member_price ) {
$on_sale = true;
} else {
$on_sale = false;
}
return $on_sale;
}
add_filter( 'woocommerce_product_is_on_sale', 'my_pmprowoo_woocommerce_product_is_on_sale', 5, 2 );
/**
* Hide the "Sale!" tag on some products that have a lower member price, but aren't really on sale.
* Feel free to tweak the code below to fit your needs.
*/
function my_pmprowoo_woocommerce_sale_flash( $sale_flash, $post, $product ) {
// remove sale flash if the "sale" price is greater than the regular price
if( (float) $product->get_price() > (float) $product->get_regular_price() ) {
$sale_flash = '';
}
// if the product didn't have a "sale" price set, hide the tag
if( $product->get_sale_price() === '' ) {
$sale_flash = '';
}
return $sale_flash;
}
add_filter( 'woocommerce_sale_flash', 'my_pmprowoo_woocommerce_sale_flash', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment