Skip to content

Instantly share code, notes, and snippets.

@suhag10
Created April 30, 2026 21:20
Show Gist options
  • Select an option

  • Save suhag10/b1b2cdded1586b3487bf3ce637262eb7 to your computer and use it in GitHub Desktop.

Select an option

Save suhag10/b1b2cdded1586b3487bf3ce637262eb7 to your computer and use it in GitHub Desktop.

Get Product Stock

global $product;

echo wc_get_stock_html( $product );

// OR

$stock_quantity = $product->get_stock_quantity();
$stock_status   = $product->get_stock_status() == 'instock' ? __('In Stock', 'woocommerce') : ($product->get_stock_status() == 'onbackorder' ? __('On Backorder', 'woocommerce') : __('Out of stock', 'woocommerce'));
$product_stock  = $stock_quantity != 0 ? $stock_quantity .' '. $stock_status : $stock_status;

echo $product_stock;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment