If product has variation Disable the Quantity in Woocommerce mini cart

天涯浪子 提交于 2020-01-25 20:34:19

问题


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


回答1:


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

$product = new WC_Product( get_the_ID() );



回答2:


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


来源:https://stackoverflow.com/questions/30851886/if-product-has-variation-disable-the-quantity-in-woocommerce-mini-cart

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