WooCommerce Advanced Product Quantities Shortcode

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

Before starting, here is an overview of the WooCommerce Advanced Product Quantities Plugin and the shortcodes it provides:

Plugin Icon
WooCommerce Advanced Product Quantities

"WooCommerce Advanced Product Quantities is a powerful add-on for your WooCommerce site. It allows you to set specific quantity increments for product sales, enhancing your online store's flexibility."

★★★★✩ (25) Active Installs: 3000+ Tested with: 4.1.39 PHP Version: false
Included Shortcodes:
  • [wpbo_quantity_message]

WooCommerce Advanced Product Quantities [wpbo_quantity_message] Shortcode

The ‘wpbo_quantity_message’ shortcode from the Woocommerce Incremental Product Quantities plugin is designed to display a note about the minimum quantity of a product. This shortcode retrieves the product’s data, checks if it’s in stock, and then fetches the minimum quantity rule. It also checks if the product is under stock management and adjusts the minimum and maximum values accordingly. If the product is out of stock, it applies a different rule. The shortcode then replaces placeholders in the text with the calculated values and displays the message. It also allows for an optional custom class to be added for styling purposes.

Shortcode: [wpbo_quantity_message]

Examples and Usage

Basic example – Displays a note for the minimum quantity of the product on a product page.

[wpbo_quantity_message]

Advanced examples

Displaying a note with custom class for styling. This will allow you to apply custom CSS to the note. You need to replace ‘my_custom_class’ with your actual CSS class.

[wpbo_quantity_message class="my_custom_class"]

Using the shortcode to display a note with custom text. The text should be placed in the ‘text’ parameter. You can use %MIN%, %MAX%, and %STEP% placeholders in your text, which will be replaced with actual values. For example:

[wpbo_quantity_message text="The minimum quantity for this product is %MIN%, maximum - %MAX%, step - %STEP%."]
Please note that these examples are based on the assumption that the ‘wpbo_quantity_message’ shortcode supports ‘class’ and ‘text’ parameters. The actual implementation may vary depending on the plugin’s code.

PHP Function Code

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

Shortcode line:

add_shortcode('wpbo_quantity_message', array( $this, 'display_minimum_quantity_note' ));

Shortcode PHP function:

                    function display_minimum_quantity_note() {
	
		global $product;
		
		if ( !is_product() ) {
			return;
		}
		
		if( $product->product_type == 'grouped' )
			return;
		
		$settings = get_option( 'ipq_options' );
		extract( $settings );
		
		// Get minimum value for product 
		$rule = wpbo_get_applied_rule( $product );
		
		// Return nothing if APQ is deactivated
		if ( $rule == 'inactive' or $rule == null ) {
			return; 
		}
		
		// Check if the product is out of stock 
		$stock = $product->get_stock_quantity();

		// Check if the product is under stock management and out of stock
		if ( strlen( $stock ) != 0 and $stock <= 0 ) {
			$min = wpbo_get_value_from_rule( 'min_oos', $product, $rule );
			$max = wpbo_get_value_from_rule( 'max_oos', $product, $rule );
		} else {
			$min = wpbo_get_value_from_rule( 'min', $product, $rule );
			$max = wpbo_get_value_from_rule( 'max', $product, $rule );
		}	

		$step = wpbo_get_value_from_rule( 'step', $product, $rule );

		// If sitewide rule is applied, convert return arrays to values
		if ( $rule == 'sitewide' and strlen( $stock ) != 0 and $stock <= 0  ) {
			if ( is_array( $min ) )
				$min = $min['min_oos'];
		
			if ( is_array( $max ) )
				$max = $max['max_oos'];
				
			if ( is_array( $step ) ) {
				$step = $step['step'];
			}
		} else if ( $rule == 'sitewide' ) {
			if ( is_array( $min ) )
				$min = $min['min'];
		
			if ( is_array( $max ) )
				$max = $max['max'];
				
			if ( is_array( $step ) ) {
				$step = $step['step'];
			}
		}
		
		// If the text is set, update and print the output
		if ( isset( $ipq_qty_text ) ) {
			$min_pattern = '/\%MIN\%/';
			$max_pattern = '/\%MAX\%/';
			$step_pattern = '/\%STEP\%/';

			$ipq_qty_text = preg_replace($min_pattern, $min, $ipq_qty_text);
			$ipq_qty_text = preg_replace($max_pattern, $max, $ipq_qty_text);
			$ipq_qty_text = preg_replace($step_pattern, $step, $ipq_qty_text);

			// Output result with optional custom class
			echo "<span";
			if ( isset( $ipq_qty_class ) and $ipq_qty_class != '' )
				echo " class='" . $ipq_qty_class . "'";
			echo ">";	
			echo $ipq_qty_text;
			echo "</span>";
		}
	}
                    

Code file location:

woocommerce-incremental-product-quantities/woocommerce-incremental-product-quantities/includes/class-ipq-actions.php

Conclusion

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