Skip to content

Instantly share code, notes, and snippets.

@markbain
Created November 9, 2018 16:20
Show Gist options
  • Save markbain/8b095e42b8dd1024624f5e54d2b2b5c2 to your computer and use it in GitHub Desktop.
Save markbain/8b095e42b8dd1024624f5e54d2b2b5c2 to your computer and use it in GitHub Desktop.
Woocommerce custom availability #wordpress #woocommerce
add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
function custom_get_availability( $availability, $_product ) {
global $product;
$stock = $product->get_total_stock();
if ( $_product->is_in_stock() ) $availability['availability'] = __($stock . ' places remaining', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
return $availability;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment