Afficher le prix MSRP dans WooCommerce WP-Lister pour Amazon
· par Daniel

Avec le plugin WP-Lister for Amazon, vous pouvez définir un prix conseillé (MSRP) pour vos produits. Mais celui-ci ne s’affiche pas comme prix barré lorsque vous saisissez un prix normal ou promotionnel.
Ajoutez le code ci-dessous dans votre fichier functions.php : le prix normal affichera toujours le prix conseillé (MSRP) s’il est défini.
/**
Change on sale to true if MSRP is set, otherwise price only shows regular
**/
add_filter( 'woocommerce_product_is_on_sale', 'we_msrp_on_sale', 10, 1);
function we_msrp_on_sale($onsale) {
global $product;
if(!$product) {
return $onsale;
}
$rrp = get_post_meta( $product->get_id(), '_msrp_price', true );
if($rrp) {
$price = $product->get_regular_price();
$onsale = true;
}
$variable_rrp = get_post_meta( $product->get_id(), 'variable_msrp', true );
if($variable_rrp) {
$price = $variable_rrp;
$onsale = true;
}
return $onsale;
}
/**
Sale price will be regular price if msrp is set
**/
add_filter( 'woocommerce_product_get_sale_price', 'we_msrp_sale_price', 10, 1);
function we_msrp_sale_price($price) {
global $product;
if(!$product) {
return $price;
}
$rrp = get_post_meta( $product->get_id(), '_msrp_price', true );
if($rrp) {
$price = $product->get_regular_price();
}
$variable_rrp = get_post_meta( $product->get_id(), 'variable_msrp', true );
if($variable_rrp) {
$price = $variable_rrp;
}
return $price;
}
/**
**/
add_filter( 'woocommerce_product_get_regular_price', 'we_msrp_price', 10, 1);
function we_msrp_price($price) {
global $product;
if(!$product) {
return $price;
}
$rrp = get_post_meta( $product->get_id(), '_msrp_price', true );
if($rrp) {
$price = $rrp;
}
$variable_rrp = get_post_meta( $product->get_id(), 'variable_msrp', true );
if($variable_rrp) {
$price = $variable_rrp;
}
return $price;
}