• Hi. I would like to display a custom message when a product is not purchable, for example on the location where the cart button would be. Instead of only hiding the cart button. Is that possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WPClever

    (@wpclever)

    Hi @danie1234

    When a product is un-purchasable, WooCommerce will hide the add to cart form by default.

    You can display your message by adding the below code to current-theme (or child-theme) / functions.php

    add_action( 'woocommerce_single_product_summary', 'woopt_single_product_summary', 25 );
    function woopt_single_product_summary() {
    	global $product;
    
    	if ( ! $product->is_purchasable() ) {
    		echo '<span style="color: red">Your message here!</span>';
    	}
    }

    And the result https://www.screencast.com/t/38lxgZFbRMV

    This is not working for me in Astra theme… Button is removed, but no message is displayed on its place.

    The button wrapper section remains on the screen, but is empty – nothing is output by this function.

    • This reply was modified 3 years, 8 months ago by espermedia.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display custom message’ is closed to new replies.