以下代码适用于单个产品,但我想将此代码用于多种产品的多种变体。
实际上,此代码是在销售价格开始之前将原始价格添加到销售价格中。
我正在制定销售计划,我希望同时显示销售价格和原始预售价格,以便客户可以看到折扣将节省多少。
function cw_change_product_price_display( $price_html ) {
global $product;
global $woocommerce;
if ( $product->is_on_sale() ) {
return $price_html;
} elseif($product->get_sale_price()){
$price =wc_price($product->get_sale_price());
return $price_html . $price;
} else {
return $price_html;
}
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
答案 0 :(得分:1)
我认为您的问题不清楚,但您似乎应该使用以下钩子来更改 WooCommerce 的可变价格。
add_filter('woocommerce_product_variation_get_price', 'cw_change_product_price_display', 99, 2);