WooCommerce没有显示可变产品的“销售价格”

时间:2019-04-17 20:12:48

标签: php wordpress woocommerce

我有一个不知道如何解决自己的问题,因此需要您的帮助。我有一个Woocommerce商店,并且当产品具有变化并且插入了Sale Price时,它现在显示在Shop page中。例如:

enter image description here

其显示在“正在销售”的产品上,但不显示产品旁边的销售价格。我摸索了一下,发现了这个功能,该功能本来可以显示可变产品的销售价格,但似乎对我的商店没有任何改变。

    //add variation sale strikethrough with original price on shop and category pages
function wc_wc20_variation_price_format( $price, $product ) {

// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price_min = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
$price_max = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[1] ) ) : wc_price( $prices[1] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice_min = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
$saleprice_max = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[1] ) ) : wc_price( $prices[1] );
if ( $price_min !== $price_max ) {
$price = '<del>' . $saleprice_min . ' - '. $saleprice_max . '</del> <ins>' . $price_min . ' - '. $price_max . '</ins>';
}
return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); 

对我的问题有帮助吗?

0 个答案:

没有答案