我已经设置了我的手推车,以显示产品的价格旁边的打折项目(见第一个产品在手推车在照片)。
这是使用以下代码实现的
function my_custom_show_sale_price_at_cart( $old_display, $cart_item, $cart_item_key ) {
$product = $cart_item['data'];
if ( $product ) {
return $product->get_price_html();
}
return $old_display;
}
add_filter( 'woocommerce_cart_item_price', 'my_custom_show_sale_price_at_cart', 10, 3 );您可以在照片中看到的问题是,这只适用于销售中的产品(售价为0.00美元的产品)。但是,优惠券代码将应用于其他两项。
我跟随这条线在结账摘要中以“您保存”的形式显示了总储蓄,包括销售和优惠券折扣。
如何显示购物车中有优惠券的商品的折扣价格?
发布于 2022-01-02 21:06:39
因此,这将根据我对您的评论的解释来更新购物车项目汇总和行项总计。
这将添加到functions.php中
function my_custom_show_sale_price_at_cart( $old_display, $cart_item, $cart_item_key ) {
$product = $cart_item['data'];
// If you just want this to show in checkout vs cart + checkout - add && is_checkout() below.
if ( $product ) {
// This item has a coupon applied.
if ( floatval( $product->get_price() ) !== number_format( $cart_item['line_total'], 2 ) / $cart_item['quantity'] ) {
// This updates the item total.
$price_html = wc_format_sale_price( $product->get_regular_price(), number_format( $cart_item['line_total'], 2 ) ) . $product->get_price_suffix();
} else {
$price_html = $product->get_price_html();
}
// This updates the line item sub-total.
add_filter(
'woocommerce_cart_item_subtotal',
function() use ( $cart_item ) {
return wc_price( $cart_item['line_total'] + $cart_item['line_tax'] );
}
);
return $price_html;
}
return $old_display;
}
add_filter( 'woocommerce_cart_item_price', 'my_custom_show_sale_price_at_cart', 10, 3 );https://stackoverflow.com/questions/70552384
复制相似问题