YITH WooCommerce Waitlist Shortcodes

Below, you’ll find a detailed guide on how to add the YITH WooCommerce Waitlist Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the YITH WooCommerce Waitlist Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the YITH WooCommerce Waitlist Plugin and the shortcodes it provides:

Plugin Icon
YITH WooCommerce Waitlist

"YITH WooCommerce Waitlist is a powerful plugin that allows your customers to join a waiting list for out-of-stock items, boosting customer engagement and sales."

★★★✩✩ (23) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [ywcwtl_waitlist_table]
  • [ywcwtl_form]

YITH WooCommerce Waitlist [ywcwtl_waitlist_table] Shortcode

The YITH WooCommerce Waiting List shortcode is a tool that generates a table listing products a user is waiting for. The related PHP code initiates this shortcode, calling the ‘yith-wcwtl-my-waitlist.php’ template. This displays the user’s waitlist in their account section.

Shortcode: [ywcwtl_waitlist_table]

Examples and Usage

Basic Example – The following shortcode is a basic usage of the yith-woocommerce-waiting-list plugin. It will display the waiting list table associated with the user’s account.

[ywcwtl_waitlist_table]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ywcwtl_waitlist_table', array( $this, 'shortcode_waitlist_my_account' ) );

Shortcode PHP function:

function shortcode_waitlist_my_account() {
			ob_start();
			wc_get_template( 'yith-wcwtl-my-waitlist.php', array(), '', YITH_WCWTL_DIR . 'templates/' );
			return ob_get_clean();
		}

Code file location:

yith-woocommerce-waiting-list/yith-woocommerce-waiting-list/includes/class.yith-wcwtl-frontend.php

YITH WooCommerce Waitlist [ywcwtl_form] Shortcode

The YITH WooCommerce Waiting List shortcode allows users to add products to a waiting list. It checks if a product can have a waitlist by verifying the product ID. If valid, it applies filters to customize the form template.

Shortcode: [ywcwtl_form]

Parameters

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

  • product_id – The unique identifier of the product for waitlist creation

Examples and Usage

Basic example – Show a waiting list form for a specific product by using its product ID

[ywcwtl_form product_id=123 /]

Advanced examples

Display a waiting list form for a product, if the product is not specified, the form will be shown for the global product in the current context.

[ywcwtl_form /]

Display a waiting list form for a product. If the product is not found or cannot have a waiting list, nothing will be shown.

[ywcwtl_form product_id=99999 /]

Note: Replace 123 or 99999 with your actual product ID.

PHP Function Code

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

Shortcode line:

add_shortcode( 'ywcwtl_form', array( $this, 'shortcode_the_form' ) );

Shortcode PHP function:

function shortcode_the_form( $atts ) {

			extract( //phpcs:ignore WordPress.PHP.DontExtract
				shortcode_atts(
					array(
						'product_id' => '',
					),
					$atts
				)
			);

			if ( $product_id ) {
				$product = wc_get_product( $product_id );
			} else {
				// get global.
				global $product;
			}

			// exit if product is null or if can't have waitlist.
			if ( is_null( $product ) || ! $product || ! $this->can_have_waitlist( $product ) ) {
				return '';
			}

			/**
			 * APPLY_FILTERS: yith_wcwtl_form_template_args
			 *
			 * Filters list of args used in the template yith-wcwtl-form.php
			 *
			 * @param array $args List of args
			 *
			 * @return array
			 */
			$args = apply_filters(
				'yith_wcwtl_form_template_args',
				array(
					'product'            => $product,
					'product_id'         => $product->get_id(),
					'message'            => get_option( 'yith-wcwtl-form-message' ),
					'label_button_add'   => get_option( 'yith-wcwtl-button-add-label' ),
					'label_button_leave' => get_option( 'yith-wcwtl-button-leave-label' ),
				)
			);

			ob_start();

			wc_get_template( 'yith-wcwtl-form.php', $args, '', YITH_WCWTL_DIR . 'templates/' );

			return ob_get_clean();
		}

Code file location:

yith-woocommerce-waiting-list/yith-woocommerce-waiting-list/includes/class.yith-wcwtl-frontend.php

Conclusion

Now that you’ve learned how to embed the YITH WooCommerce Waitlist Plugin shortcodes, 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 *