Last active
August 29, 2015 14:04
-
-
Save jackgregory/c9912143cc4a8a13f4e5 to your computer and use it in GitHub Desktop.
WooCommerce - Add a low stock note to cart items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_cart_item_name', 'cart_low_stock_note', 10, 3 ); | |
function cart_low_stock_note( $title, $cart_item, $cart_item_key ) { | |
if( $cart_item ) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
$output = ''; | |
$output.= $title; | |
// threshold | |
if( $_product->get_stock_quantity() <= 4 ) { | |
$output.= '<p class="stock-note">' . sprintf( __( 'Note: Only %d left in stock', 'woocommerce' ), $_product->get_stock_quantity() ) .'</p>'; | |
} | |
return $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment