Php WooCommerce:如果产品数量大于1,则仅在结帐时显示产品数量

Php WooCommerce:如果产品数量大于1,则仅在结帐时显示产品数量,php,wordpress,woocommerce,woocommerce-theming,Php,Wordpress,Woocommerce,Woocommerce Theming,我想在WooCommerce结帐中隐藏产品数量,并用产品标题下方的额外行替换标题旁边的“x 1” 但只有当订单中的产品数量超过1个时,才应显示产品数量 add_filter( 'woocommerce_checkout_cart_item_quantity', 'customizing_checkout_item_quantity', 10, 3); function customizing_checkout_item_quantity( $quantity_html, $cart_item,

我想在WooCommerce结帐中隐藏产品数量,并用产品标题下方的额外行替换标题旁边的“x 1”

但只有当订单中的产品数量超过1个时,才应显示产品数量

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', 'woocommerce') . ': <strong>' . $cart_item['quantity'] . '</strong></span>';

    return $quantity_html;
}
我发现下面的代码为数量添加了额外的行。但我不知道只有当订单中有>1个产品时如何显示数量

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', 'woocommerce') . ': <strong>' . $cart_item['quantity'] . '</strong></span>';

    return $quantity_html;
}
add_filter('woocommerce_checkout_cart_item_quantity','customize_checkout_item_quantity',10,3);
函数自定义\结帐\项目\数量($quantity\ html、$cart\项目、$cart\项目\键){
$quantity_html='
“.'uuu'('Quantity','woocommerce'):”.$cart\u item['Quantity'。”; 返回$quantity\u html; }
代码来自此答案:


如果订单中的产品超过一种,是否有办法检查数量并显示行?

要检查每个订单中是否有一种以上的产品,我会选择以下条件:

if ( WC()->cart->get_cart_contents_count() > 1 ) {
     // more than 1 product per order
}

我想出来了。函数中已存在数量:

这是我的解决方案:

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 ) {

    $cart_item_quantity_count = $cart_item['quantity'];
    if ( $cart_item_quantity_count > 1 ) :
        $quantity_html = '<br> <span class="product-quantity">' . __('Quantity', 'woocommerce') . ': <strong>' . $cart_item['quantity'] . '</strong></span>';
    else:
        $quantity_html = '';
    endif;

    return $quantity_html;

}
add_filter('woocommerce_checkout_cart_item_quantity','customize_checkout_item_quantity',10,3);
函数自定义\结帐\项目\数量($quantity\ html、$cart\项目、$cart\项目\键){
$cart_item_quantity_count=$cart_item['quantity'];
如果($cart\u item\u quantity\u count>1):
$quantity\u html='
'.'quantity','woocommerce')。:'.$cart\u item['quantity'.'; 其他: $quantity_html=''; endif; 返回$quantity\u html; }
谢谢,但我需要检查购物车中是否有多个单一产品(sku)项目。不是每个购物车的产品。