如果产品有变化,请禁用Woocommerce迷你购物车中的数量


If product has variation Disable the Quantity in Woocommerce mini cart

在我的主题中,如果产品有变化 是显示一些类似 1x$18=$18 如果产品有变化,如何删除数量。我需要类似的东西包 x $18 =$18 但如果产品没有变化,它会显示原样。是否有任何"如果条件申请变更"?请帮助我。

 <?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>

我正在尝试制作这个

<?php 
if( $product->is_type( 'simple' ) ){
  echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); 
} else{ 
  apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( $product_price ) . '</span>', $cart_item, $cart_item_key ); 
}
$product = new WC_Product( get_the_ID() );
?>

但不是工作

将此行移动到代码顶部而不是代码末尾。

$product = new WC_Product( get_the_ID() );

最后我解决了问题 现在请检查这个在我的主题文件上 检查这个 这里

<?php 
global $woocommerce, $product, $post;
    $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    if( $_product->is_type( 'simple' ) ){
        echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); 
    }else{ 
        echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( $product_price ) . '</span>', $cart_item, $cart_item_key ); 
    } 
?>