get product by category id in woocommerce code example

Example 1: woocommerce get product id

global $product;
$product->get_id();

Example 2: get product price woocommerce of specific id

$product = wc_get_product( $post_id );

$product->get_regular_price();
$product->get_sale_price();
$product->get_price();

Example 3: get stock product woocommerce by id

$product_id = 1100;
$product = wc_get_product($product_id);
echo $product->get_stock_quantity();

Example 4: is product category woocommerce

if( is_product_category() ) {
	// yay, we are on a product category page!
} else {
 
}

Tags:

Php Example