【发布时间】:2020-11-04 14:52:06
【问题描述】:
我添加了基于每个购物车商品数量的累进定价。我正在努力的是从产品中反映$default_price(而不是现在手动添加的价格),并像这样设置新价格的布局(default_price 有删除线):
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 20, 1);
function add_custom_price( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
foreach ( $cart->get_cart() as $item ) {
$quantity = $item['quantity'];
$discount_price = 0.008333333333;
$default_price = 4.25;
$minimum = 10;
$maximum = 100;
if( $quantity > $minimum ) {
if( $quantity > $maximum ) {
$new_price = $default_price - ($discount_price * ($maximum - $minimum));
}
else {
$new_price = $default_price - ($discount_price * ($quantity - $minimum));
}
$item['data']->set_price( '<del>' . $default_price . '</del> <strong>' . $new_price . '</strong>');
}
}
}
编码的$item['data']->set_price( '<del>' . $default_price . '</del> <strong>' . $new_price . '</strong>'); 是错误的,但是我该如何反映它以便它可以接受html元素?
【问题讨论】:
标签: php wordpress woocommerce cart strikethrough