Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce conditional to test if a Product is Simple or Variable.
<?php
/**
* Is a WooCommerce Product Simple or Variable
*
* see http://wordpress.org/support/topic/condition-to-check-if-product-is-simple-or-variable
*/
if( $product->is_type( 'simple' ) ){
// a simple product
} elseif( $product->is_type( 'variable' ) ){
// a variable product
}
// If you need a Product object for the above:
$product = new WC_Product( get_the_ID() );
@Exclutips

This comment has been minimized.

Copy link

commented Jun 15, 2015

How I change the below code to

' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '', $cart_item, $cart_item_key ); ?>

Changes but not work.

is_type( 'simple' ) ){ // a simple product echo apply_filters( 'woocommerce_widget_cart_item_quantity', '' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '', $cart_item, $cart_item_key ); } else{ // a variable product apply_filters( 'woocommerce_widget_cart_item_quantity', '' . sprintf( $product_price ) . '', $cart_item, $cart_item_key ); } // If you need a Product object for the above: $product = new WC_Product( get_the_ID() ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.