【发布时间】:2020-11-13 09:08:19
【问题描述】:
我正在尝试为我的可变产品显示自定义价格范围。 我设法插入了一个包含常规(最低和最高)价格和销售(最低和最高)价格的价格范围。
这是我的代码尝试:
add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 );
function custom_price_format( $price, $product ) {
// Main Price
$regular_priceMin = $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : $product->get_regular_price();
$regular_priceMax = $product->is_type('variable') ? $product->get_variation_regular_price( 'max', true ) : $product->get_regular_price();
$sale_priceMin = $product->is_type('variable') ? $product->get_variation_sale_price( 'min', true ) : $product->get_sale_price();
$sale_priceMax = $product->is_type('variable') ? $product->get_variation_sale_price( 'max', true ) : $product->get_sale_price();
if ( $regular_priceMin !== $sale_priceMin && $product->is_on_sale()) {
$price = '<p class="teste"><del>' . wc_price($regular_priceMin). 'a' . wc_price($regular_priceMax) . '</del></p> <ins>' . wc_price($sale_priceMin) . '</ins>';
}
return $price;
}
但是,一些销售价格具有相同的值并且格式不正确。
它创建了 3 行:
- 一个代表最低价格,
- 另一个字母“a”
- 另一个是最高价格值。
我怎样才能正确地组织这个?
标签<del>标签不在同一行。
如何解决这个问题?我做错了什么?
【问题讨论】:
-
尝试改写您的问题,因为它不清楚且无法理解。
-
我更新问题谢谢!
标签: php wordpress woocommerce hook-woocommerce price