Get product by post ID in WooCommerce

$product = wc_get_product( $post_id );
// now you can call WC_Product class functions, e.g.:
if ( $product->is_type( 'variable' ) ) {
      // do something...
}

Leave a Comment