Back In Stock Notifier For Woocommerce Shortcode

Below, you’ll find a detailed guide on how to add the Back In Stock Notifier For Woocommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Back In Stock Notifier For Woocommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Back In Stock Notifier For Woocommerce Plugin and the shortcodes it provides:

Plugin Icon
Back In Stock Notifier for WooCommerce | WooCommerce Waitlist Pro

"Back In Stock Notifier for WooCommerce | WooCommerce Waitlist Pro is a useful plugin that notifies customers when out-of-stock products are available again, boosting sales and customer satisfaction."

★★★★☆ (95) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [cwginstock_subscribe_form]

Back In Stock Notifier For Woocommerce [cwginstock_subscribe_form] Shortcode

The ‘cwginstock_subscribe_form’ shortcode is designed to display a subscription form for out-of-stock WooCommerce products. It accepts product and variation IDs as parameters. If a valid variation ID is provided, it displays a form for the specific product variation. If only a product ID is provided, it shows a form for the product. The shortcode bypasses reCAPTCHA for variations.

Shortcode: [cwginstock_subscribe_form]

Parameters

Here is a list of all possible cwginstock_subscribe_form shortcode parameters and attributes:

  • product_id – The specific ID of the product in WooCommerce.
  • variation_id – The ID of the specific product variation in WooCommerce.

Examples and Usage

Basic example – A simple shortcode that displays the subscribe form for a specific product using the product’s ID.

[cwginstock_subscribe_form product_id=101 /]

Advanced examples:

Using the shortcode to display the subscribe form for a specific product and its variation. The product and variation are identified by their respective IDs. If the variation is not found, it will display the subscribe form for the product only.

[cwginstock_subscribe_form product_id=101 variation_id=202 /]

Using the shortcode to display the subscribe form for a specific product. If the product is not found, it will not display anything.

[cwginstock_subscribe_form product_id=101 /]

Using the shortcode to display the subscribe form for a specific variation of a product. If the variation is not found, it will not display anything.

[cwginstock_subscribe_form variation_id=202 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cwginstock_subscribe_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cwginstock_subscribe_form', array( $this, 'subscribe_form_shortcode' ) );

Shortcode PHP function:

function subscribe_form_shortcode( $atts ) {
			ob_start();
			$att = shortcode_atts( array(
				'product_id' => '',
				'variation_id' => ''
			), $atts );
			$product_id = isset( $att['product_id'] ) ? (int) $att['product_id'] : false;
			$variation_id = isset( $att['variation_id'] ) ? (int) $att['variation_id'] : false;

			if ( $variation_id && ( $variation_id > 0 ) ) {
				$product = wc_get_product( $product_id );
				$variation = wc_get_product( $variation_id );
				if ( $product && $variation ) {
					add_filter( 'cwginstock_bypass_recaptcha', array( $this, 'bypass_recaptcha_for_variation' ), 10, 3 );
					echo do_shortcode( $this->display_subscribe_box( $product, $variation ) );
				}
			} elseif ( $product_id && ( $product_id > 0 ) ) {
				$product = wc_get_product( $product_id );
				if ( $product ) {
					echo do_shortcode( $this->display_subscribe_box( $product ) );
				}
			}
			return ob_get_clean();
		}

Code file location:

back-in-stock-notifier-for-woocommerce/back-in-stock-notifier-for-woocommerce/includes/frontend/class-product.php

Conclusion

Now that you’ve learned how to embed the Back In Stock Notifier For Woocommerce Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *