WPC Grouped Product for WooCommerce Shortcodes

Below, you’ll find a detailed guide on how to add the WPC Grouped Product for WooCommerce 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 WPC Grouped Product for WooCommerce Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WPC Grouped Product for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
WPC Grouped Product for WooCommerce

"WPC Grouped Product for WooCommerce is a powerful plugin that enhances your eCommerce store by allowing you to group and display products together, boosting customer engagement and sales."

★★★★★ (23) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [woosg]
  • [woosg_form]

WPC Grouped Product for WooCommerce [woosg] Shortcode

The WPC Grouped Product shortcode is a functional tool that displays specific grouped items on your site. It uses the ‘woosg’ shortcode, which initiates the ‘shortcode’ function. This function extracts the ‘id’ attribute from the shortcode and uses it to display the related grouped items. The output is then returned and displayed on the site.

Shortcode: [woosg]

Parameters

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

  • id – The unique identifier for the grouped product

Examples and Usage

Basic example – The simplest way to use the ‘woosg’ shortcode is to reference the ID of the grouped product you want to display. This example will display the grouped product with ID 1.

[woosg id=1 /]

Advanced examples

Using the shortcode to display multiple grouped products by referencing their IDs. This example will display the grouped products with IDs 1, 2, and 3. Please note that the IDs are separated by commas without spaces.

[woosg id=1,2,3 /]

Using the shortcode to display a grouped product and override the default settings. This example will display the grouped product with ID 1, but with custom settings. The ‘show_price’ attribute is set to ‘false’ to hide the price, and the ‘show_quantity’ attribute is set to ‘true’ to display the quantity.

[woosg id=1 show_price=false show_quantity=true /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'woosg', [ $this, 'shortcode' ] );

Shortcode PHP function:

                    function shortcode( $attrs ) {
			$attrs = shortcode_atts( [ 'id' => null ], $attrs );

			ob_start();
			self::show_items( $attrs['id'] );

			return ob_get_clean();
		}
                    

Code file location:

wpc-grouped-product/wpc-grouped-product/includes/class-woosg.php

WPC Grouped Product for WooCommerce [woosg_form] Shortcode

The WPC Grouped Product shortcode is a powerful tool for product management. It allows you to display a product form on your website. The shortcode retrieves product data based on the provided ID. If no ID is given, it uses the global product ID. If the product has variations, it enqueues the ‘wc-add-to-cart-variation’ script. It also calls a function to display items related to the product ID and applies a template for a simple ‘add-to-cart’ button.

Shortcode: [woosg_form]

Parameters

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

  • id – Unique ID of the WooCommerce product

Examples and Usage

Basic example – Display a specific product form using its ID:

[woosg_form id=123 /]

Here, replace ‘123’ with the ID of the product you want to display. This shortcode will display the product form for the product with the specified ID.

Advanced examples

Display a product form without specifying a product ID:

[woosg_form /]

In this case, the shortcode will display the product form for the current product. This is useful when you want to use the same shortcode across multiple product pages.

Display a product form and load scripts for variable products:

[woosg_form id=456 /]

Replace ‘456’ with the ID of your variable product. This shortcode will display the product form for the specified product and also load the necessary scripts for handling variable products. This is useful when your product has variations like different sizes or colors.

PHP Function Code

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

Shortcode line:

add_shortcode( 'woosg_form', [ $this, 'shortcode_form' ] );

Shortcode PHP function:

                    function shortcode_form( $attrs ) {
			global $product;

			$attrs      = shortcode_atts( [ 'id' => null ], $attrs );
			$product_id = $attrs['id'];

			if ( ! $product_id ) {
				if ( $product ) {
					$product_id = $product->get_id();
				}
			} else {
				$product = wc_get_product( $product_id );
			}

			if ( ! $product_id || ! $product ) {
				return '';
			}

			ob_start();

			if ( $product->has_variables() ) {
				wp_enqueue_script( 'wc-add-to-cart-variation' );
			}

			self::show_items( $product_id );

			wc_get_template( 'single-product/add-to-cart/simple.php' );

			return ob_get_clean();
		}
                    

Code file location:

wpc-grouped-product/wpc-grouped-product/includes/class-woosg.php

Conclusion

Now that you’ve learned how to embed the WPC Grouped Product for WooCommerce 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 *