Change Woocommerce product quantity in checkout table

好久不见. 提交于 2020-01-13 18:36:26

问题


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?


回答1:


This can be done in multiple ways:

1) Overriding template checkout/review-order.php via your child theme.

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;
}

Code goes in function.php file of the active child theme (or active theme).

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;
}

Code goes in function.php file of the active child theme (or active theme).

All code is tested and works.



来源:https://stackoverflow.com/questions/48232454/change-woocommerce-product-quantity-in-checkout-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!