wc_format_stock_for_display

Format the stock amount ready for display based on settings.

Description

(string) wc_format_stock_for_display( (WC_Product) $product ); 

Returns (string)

Parameters (1)

0. $product (WC_Product)
Product object for which the stock you need to format.

Usage

  1. if ( !function_exists( 'wc_format_stock_for_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
  3.  
  4. // Product object for which the stock you need to format. 
  5. $product = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_format_stock_for_display($product); 
  9.  

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_format_stock_for_display( $product ) { 
  2. $display = __( 'In stock', woocommerce ); 
  3. $stock_amount = $product->get_stock_quantity(); 
  4.  
  5. switch ( get_option( 'woocommerce_stock_format' ) ) { 
  6. case 'low_amount' : 
  7. if ( $stock_amount <= get_option( 'woocommerce_notify_low_stock_amount' ) ) { 
  8. $display = sprintf( __( 'Only %s left in stock', woocommerce ), wc_format_stock_quantity_for_display( $stock_amount, $product ) ); 
  9. break; 
  10. case '' : 
  11. $display = sprintf( __( '%s in stock', woocommerce ), wc_format_stock_quantity_for_display( $stock_amount, $product ) ); 
  12. break; 
  13.  
  14. if ( $product->backorders_allowed() && $product->backorders_require_notification() ) { 
  15. $display .= ' ' . __( '(can be backordered)', woocommerce ); 
  16.  
  17. return $display;