Last active
July 10, 2021 17:39
-
-
Save damiencarbery/757308c10af2ca103330b4b4673e6a49 to your computer and use it in GitHub Desktop.
WooCommerce - Display only Sale Price https://www.damiencarbery.com/2018/04/woocommerce-display-only-sale-price/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="price"> | |
<del><span class="woocommerce-Price-amount amount"> | |
<span class="woocommerce-Price-currencySymbol">€</span>65.00 | |
</span></del> | |
<ins><span class="woocommerce-Price-amount amount"> | |
<span class="woocommerce-Price-currencySymbol">€</span>55.00 | |
</span></ins> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="price"> | |
<span class="woocommerce-Price-amount amount"> | |
<span class="woocommerce-Price-currencySymbol">€</span>55.00 | |
</span> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Show Only Sale Price (variable products) | |
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_variable_price_html', 'dcwd_variable_price', 10, 2 ); | |
function dcwd_variable_price( $price_html, $product ) { | |
if ( $product->is_on_sale() ) { | |
$prices = $product->get_variation_prices( true ); | |
$min_price = current( $prices['price'] ); | |
$price = wc_price( $min_price ); | |
return 'From: ' . $price; | |
} | |
return $price_html; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.2 | |
*/ | |
// For simple products. | |
add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 ); | |
function dcwd_sale_price( $price, $regular_price, $sale_price ) { | |
/*global $product; | |
// Show regular and sale price for specified product IDs | |
if ( in_array( $product->get_id(), array( 1, 2, 3, 28 ) ) ) { | |
return $price; | |
} | |
// Show regular and sale price if product is in any of the specified categories. | |
if ( has_term( array( 'hoodies', 'accessories', 'tshirts' ), 'product_cat', $product->get_id() ) ) { | |
return $price; | |
}*/ | |
return wc_price( $sale_price ); | |
} | |
// For variable products. | |
add_filter( 'woocommerce_variable_price_html', 'dcwd_variable_price', 10, 2 ); | |
function dcwd_variable_price( $price_html, $product ) { | |
if ( $product->is_on_sale() ) { | |
/*// Show regular and sale price for specified product IDs | |
if ( in_array( $product->get_id(), array( 1, 2, 3, 7932 ) ) ) { | |
return $price_html; | |
} | |
// Show regular and sale price if product is in any of the specified categories. | |
if ( has_term( array( 'hoodies', 'accessories', 'tshirts' ), 'product_cat', $product->get_id() ) ) { | |
return $price_html; | |
}*/ | |
$prices = $product->get_variation_prices( true ); | |
$min_price = current( $prices['price'] ); | |
$price = wc_price( $min_price ); | |
return 'From: ' . $price; | |
} | |
return $price_html; | |
} |
Hi Damien,
That's the one! I'm happy to share the code with you so you can have a look at it (attached zip)
Thank you
Lyse Tremblay
…-----Original Message-----From: "Damien Carbery" <notifications@github.com>Sent: Friday, 21 June, 2019 9:33amTo: "damiencarbery" <damiencarbery@noreply.github.com>Cc: "Lyse" <tremblay.lyse@tremblayprudly.com>, "Comment" <comment@noreply.github.com>Subject: Re: damiencarbery/regular-and-sale-price.html
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.
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
I didn't see any zip attached. Email me directly at damien@damiencarbery.com
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
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.