Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conschneider/977545250b3783acd632ab3d39bff8df to your computer and use it in GitHub Desktop.
Save conschneider/977545250b3783acd632ab3d39bff8df to your computer and use it in GitHub Desktop.
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
*/
//get product right first to access methods of WC_Product()
$product = wc_get_product( get_the_ID() );
//Conditional check
if( $$product->is_type( 'simpe' ) ){
// a simple product
} elseif( $product->is_type( 'variable' ) && $product->has_child() ){
// a variable product
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment