Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Last active November 24, 2016 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/326c933ded878d943229 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/326c933ded878d943229 to your computer and use it in GitHub Desktop.
Replaces product price by out of stock message in case a variable product is out of stock (Woocommerce)
<?php
//Replaces product price by out of stock message in case a variable product is out of stock (optional)
add_action('woocommerce_before_single_product_summary',function(){
if(is_product()){
global $product;
if(!$product->is_in_stock()){
remove_action('woocommerce_single_variation','woocommerce_single_variation');
remove_action('woocommerce_single_product_summary','woocommerce_template_single_price');
add_action('woocommerce_single_product_summary',function(){
?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php
});
}
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment