在结帐表中更改Woocommerce产品数量 [英] Change Woocommerce product quantity in checkout table

查看:70
本文介绍了在结帐表中更改Woocommerce产品数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改Woocommerce在订单查看表中显示产品数量的方式。我希望数量在产品名称下方而不是之后。

I would like to change the way Woocommerce is displaying the product quantity in the order review table. I would like the quantity to be underneath the product name instead of after it.

我发现这篇帖子很有帮助,但是代码仅更改了可变产品的数量布局。

I found this post which helped, but the code only changes the quantity layout for variable products.

如何为每种产品(甚至是简单的产品)进行更改?

How can I change it for EVERY product, even simple ones?

推荐答案

这可以通过多种方式完成:

This can be done in multiple ways:

1)覆盖模板 checkout / review-order.php 通过您的孩子主题

2)自定义产品商品名称:

2) Customizing the product item name:

add_filter( 'woocommerce_cart_item_name', 'customizing_checkout_item_name', 10, 3);
function customizing_checkout_item_name( $item_name, $cart_item, $cart_item_key ) {
    if( is_checkout() )
        $item_name .= '<br>';

    return $item_name;
}

代码位于活动子主题的function.php文件中(

3)自定义产品数量最佳方式

3) Customizing the product item quantity (the best way):

add_filter( 'woocommerce_checkout_cart_item_quantity', 'customizing_checkout_item_quantity', 10, 3);
function customizing_checkout_item_quantity( $quantity_html, $cart_item, $cart_item_key ) {
    $quantity_html = ' <br>
            <span class="product-quantity">' . __('Quantity:') . ' <strong>' . $cart_item['quantity'] . '</strong></span>';

    return $quantity_html;
}

代码位于活动子主题的function.php文件中(或活动主题)。

所有代码均已通过测试并可以正常工作。

All code is tested and works.

这篇关于在结帐表中更改Woocommerce产品数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆