【发布时间】:2019-05-29 05:28:27
【问题描述】:
我找到了以下代码(来自 here),它使我能够在 WooCommerce 上的可变价格产品上显示:'From: £10'(在 £10 - £50 的产品上) .我想有效地扭转这种情况并显示“最多:50 英镑”。
我试图调整下面的代码,但就是想不通:
function custom_variable_price_range( $price_html, $product ) {
$prefix = sprintf('%s: ', __('From', 'woocommerce') );
$min_regular_price = $product->get_variation_regular_price( 'min', true );
$min_sale_price = $product->get_variation_sale_price( 'min', true );
$max_price = $product->get_variation_price( 'max', true );
$min_price = $product->get_variation_price( 'min', true );
$price_html = ( $min_sale_price == $min_regular_price ) ? wc_price( $min_regular_price ) :
'<del>' . wc_price( $min_regular_price ) . '</del>' . '<ins>' . wc_price( $min_sale_price ) . '</ins>';
return ( $min_price == $max_price ) ? $price_html : sprintf( '%s%s', $prefix, $price_html );
}
add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_range', 10, 2 );
这就是我想要的样子:
感谢任何帮助。
【问题讨论】:
标签: php wordpress woocommerce product price