首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电子商务如何在购物车中显示产品的销售价格

电子商务如何在购物车中显示产品的销售价格
EN

Stack Overflow用户
提问于 2022-01-01 22:38:23
回答 1查看 735关注 0票数 0

我已经设置了我的手推车,以显示产品的价格旁边的打折项目(见第一个产品在手推车在照片)。

结帐截图

这是使用以下代码实现的

代码语言:javascript
复制
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美元的产品)。但是,优惠券代码将应用于其他两项。

我跟随这条线在结账摘要中以“您保存”的形式显示了总储蓄,包括销售和优惠券折扣。

如何显示购物车中有优惠券的商品的折扣价格?

EN

回答 1

Stack Overflow用户

发布于 2022-01-02 21:06:39

因此,这将根据我对您的评论的解释来更新购物车项目汇总和行项总计。

这将添加到functions.php中

代码语言:javascript
复制
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 );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70552384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档