问题
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