Customize WooCommerce Notice for Password Protected Products

You’re using WooCommerce for your online business. Anticipating all the potential risks, you’ve already password protected your online products from unauthorized access, which is great.

You’re also advertising your products on social media site e.g. Facebook to boost sales and enhance your brand image. In order to make it more convenient for your members, you want all VIP members to be able to view and purchase the products immediately from the Facebook links. At the same time, inviting those non-members to sign up via a direct link with a customized message before accessing your website.

By default, WooCommerce prevents password protected products from being added to cart. That’s why you will see the following message popup when trying to purchase a protected product.

However, the boring default WooCommerce notice shown up to your valued customers bothers you so much.

You want to bring a much better shopping experience for them as well as expanding your customer base with some interesting words? No worries, we’re here to guide you through this.

There’re only 2 simple steps to customize your WooCommerce notice for password protected products:

Step 1: Put this code at the end of your (child) theme functions.php

Step 2: Replace the text in bold with your desired text.

Insert the link to your VIP sign up page accordingly. We’ve put in this example.

function customize_woocommerce_notice( $message ) {
    if (strpos($message,'This product is protected and cannot be 
purchased.') !== false) {
       // change your message accordingly
       $message = 'Not a Vip Member yet?  
<a href="" target="_blank">Sign up</a> 
for free and access all our catalogue before the sale event starts.';
    return $message;
add_filter( 'woocommerce_add_error', 'customize_woocommerce_notice' );

Once it’s done, you will see the new customized message shown up as below


Lasted updated on August 31, 2020