If product has variation Disable the Quantity in Woocommerce mini cart

1.4k views Asked by At

In My theme there If the product has variation Is show some thing like 1x$18=$18 how to remove the Quantity if the product has variations. I need Something Like pack x $18 =$18 but If the Product has no variation it show as it is . Is there any "If condition to apply for variation"? Please help me.

 <?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 ); ?>

I am Trying to make this

<?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() );
?>

But not Work

2

There are 2 answers

1
BenB On

Move this line to top of code instead of end of code.

$product = new WC_Product( get_the_ID() );
1
AudioBubble On

Al Last I solve the problem Check this please now this on my theme file Check this here

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