wc_get_stock_html

Get HTML to show product stock.

Description

(string) wc_get_stock_html( (WC_Product) $product ); 

Returns (string)

Parameters (1)

0. $product (WC_Product)
The product.

Usage

  1. if ( !function_exists( 'wc_get_stock_html' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_stock_html($product); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function wc_get_stock_html( $product ) { 
  2.  
  3. $html = ''; 
  4. $availability = $product->get_availability(); 
  5.  
  6. if ( ! empty( $availability['availability'] ) ) { 
  7. ob_start(); 
  8.  
  9. wc_get_template( 'single-product/stock.php', array( 
  10. 'product' => $product,  
  11. 'class' => $availability['class'],  
  12. 'availability' => $availability['availability'],  
  13. ) ); 
  14.  
  15. $html = ob_get_clean(); 
  16.  
  17. if ( has_filter( 'woocommerce_stock_html' ) ) { 
  18. wc_deprecated_function( 'The woocommerce_stock_html filter', '', 'woocommerce_get_stock_html' ); 
  19. $html = apply_filters( 'woocommerce_stock_html', $html, $availability['availability'], $product ); 
  20.  
  21. return apply_filters( 'woocommerce_get_stock_html', $html, $product );