Below, you’ll find a detailed guide on how to add the Min Max Default Quantity 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 Min Max Default Quantity for WooCommerce Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Min Max Default Quantity for WooCommerce Plugin and the shortcodes it provides:
"MinMax Default Quantity for WooCommerce is a handy plugin. It allows you to set minimum, maximum, and default quantities for your WooCommerce products, enhancing your online store management."
- [alg_wc_pq_min_product_qty]
- [alg_wc_pq_max_product_qty]
- [alg_wc_pq_product_qty_step]
- [alg_wc_pq_product_qty_price_unit]
- [alg_wc_pq_translate]
Min Max Default Quantity for WooCommerce [alg_wc_pq_min_product_qty] Shortcode
The ‘alg_wc_pq_min_product_qty’ shortcode is a part of the product-quantity-for-woocommerce plugin. It’s used to set the minimum product quantity a customer can purchase. This shortcode works by calling the ‘min_product_qty’ function. The function outputs the minimum quantity set for a product. This is useful for store owners who want to enforce a minimum purchase limit.
Shortcode: [alg_wc_pq_min_product_qty]
Examples and Usage
Basic example – The shortcode below will output the minimum quantity of a product that can be purchased. It is the most basic usage of the ‘alg_wc_pq_min_product_qty’ shortcode.
[alg_wc_pq_min_product_qty id="99"]
Advanced examples
Adding a product ID and a title attribute to the shortcode. If the product with the given ID is not found, the shortcode will try to output the minimum quantity for a product with the given title.
[alg_wc_pq_min_product_qty id="99" title="Product Title"]
Using the shortcode with a ‘class’ attribute. The output will be wrapped in a div with the specified class, allowing for more control over the styling of the output.
[alg_wc_pq_min_product_qty id="99" class="my-custom-class"]
Combining multiple attributes in the shortcode. This example includes a product ID, a title, and a class. The shortcode will first try to find a product with the given ID. If not found, it will try to find a product with the given title. The output will be wrapped in a div with the specified class.
[alg_wc_pq_min_product_qty id="99" title="Product Title" class="my-custom-class"]
PHP Function Code
In case you have difficulties debugging what causing issues with [alg_wc_pq_min_product_qty]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'alg_wc_pq_min_product_qty', array( $this, 'min_product_qty' ) );
Shortcode PHP function:
function min_product_qty( $atts, $content = '' ) {
return $this->output_shortcode( $this->get_min_or_max_or_step( 'min' ), $atts );
}
Code file location:
product-quantity-for-woocommerce/product-quantity-for-woocommerce/includes/class-alg-wc-pq-shortcodes.php
Min Max Default Quantity for WooCommerce [alg_wc_pq_max_product_qty] Shortcode
The ‘alg_wc_pq_max_product_qty’ shortcode is a feature of the Product Quantity for WooCommerce plugin. It sets the maximum quantity of a product that can be purchased. This shortcode calls the ‘max_product_qty’ function. This function retrieves the maximum product quantity limit set by the user and displays it on the product page.
Shortcode: [alg_wc_pq_max_product_qty]
Examples and Usage
Basic Example – The shortcode below sets the maximum quantity of a product that can be added to the cart. This is useful for limiting the purchase of certain items.
[alg_wc_pq_max_product_qty id=5 /]
Advanced Examples
Here, the shortcode is used to set the maximum quantity of a product, as well as the minimum quantity. This is ideal for situations where you want to enforce a certain quantity range for a product.
[alg_wc_pq_max_product_qty id=5 min=2 max=10 /]
In this example, the shortcode is used to set the maximum quantity of a product, the minimum quantity, and the step value. The step value determines the quantity increments a customer can choose between. For example, if the step value is set to 2, customers can only add the product to their cart in multiples of 2.
[alg_wc_pq_max_product_qty id=5 min=2 max=10 step=2 /]
Please note that in these examples, ‘id’ refers to the product ID, ‘min’ refers to the minimum quantity, ‘max’ refers to the maximum quantity, and ‘step’ refers to the quantity increment.
PHP Function Code
In case you have difficulties debugging what causing issues with [alg_wc_pq_max_product_qty]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'alg_wc_pq_max_product_qty', array( $this, 'max_product_qty' ) );
Shortcode PHP function:
function max_product_qty( $atts, $content = '' ) {
return $this->output_shortcode( $this->get_min_or_max_or_step( 'max' ), $atts );
}
Code file location:
product-quantity-for-woocommerce/product-quantity-for-woocommerce/includes/class-alg-wc-pq-shortcodes.php
Min Max Default Quantity for WooCommerce [alg_wc_pq_product_qty_step] Shortcode
The ‘alg_wc_pq_product_qty_step’ shortcode is used to define the quantity step for a WooCommerce product. It’s part of the Product Quantity for WooCommerce plugin. This shortcode outputs the step value, which dictates the increments in which a product’s quantity can be adjusted. For example, if the step value is 2, customers can only purchase the product in multiples of 2.
Shortcode: [alg_wc_pq_product_qty_step]
Examples and Usage
Basic example – Displaying the quantity step of a product using its product ID.
[alg_wc_pq_product_qty_step id="99"]
Advanced examples
Displaying the quantity step of a product using its product ID, along with additional attributes such as ‘min’ and ‘max’ values.
[alg_wc_pq_product_qty_step id="99" min="1" max="10"]
Using the shortcode to display the quantity step of a product by referencing both product ID and title. The product will first try to load by ID, but if not found, it will try to load by title.
[alg_wc_pq_product_qty_step id="99" title="Sample Product"]
Please note that the ‘id’ attribute in the shortcode refers to the product ID in your WooCommerce store. The ‘min’ and ‘max’ attributes are optional and can be used to specify the minimum and maximum quantity steps for the product. The ‘title’ attribute is also optional and can be used as a fallback when the product ID is not found.
PHP Function Code
In case you have difficulties debugging what causing issues with [alg_wc_pq_product_qty_step]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'alg_wc_pq_product_qty_step', array( $this, 'product_qty_step' ) );
Shortcode PHP function:
function product_qty_step( $atts, $content = '' ) {
return $this->output_shortcode( $this->get_min_or_max_or_step( 'step' ), $atts );
}
Code file location:
product-quantity-for-woocommerce/product-quantity-for-woocommerce/includes/class-alg-wc-pq-shortcodes.php
Min Max Default Quantity for WooCommerce [alg_wc_pq_product_qty_price_unit] Shortcode
The ‘alg_wc_pq_product_qty_price_unit’ shortcode is a part of the Product Quantity for WooCommerce plugin. It is used to output the price per unit of a product. This shortcode fetches the ‘price_unit’ attribute of a product and displays it. It helps in clearly communicating the cost per unit, making price comparisons easier for customers.
Shortcode: [alg_wc_pq_product_qty_price_unit]
Examples and Usage
Basic example – A simple usage of the ‘alg_wc_pq_product_qty_price_unit’ shortcode. It will output the price unit of a product based on its ID.
[alg_wc_pq_product_qty_price_unit id="123" /]
Advanced examples
Using the shortcode to display the price unit of a product by referencing both ID and a specific attribute. The shortcode will first try to load by ID, but if not found, it will try to load by attribute.
[alg_wc_pq_product_qty_price_unit id="123" attribute="color" /]
Using the shortcode to display the price unit of a product by referencing both ID and a specific attribute value. The shortcode will first try to load by ID, but if not found, it will try to load by attribute and its value.
[alg_wc_pq_product_qty_price_unit id="123" attribute="color" value="red" /]
Using the shortcode to display the price unit of a product by referencing its SKU. The shortcode will try to load the product based on its SKU.
[alg_wc_pq_product_qty_price_unit sku="abc123" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [alg_wc_pq_product_qty_price_unit]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'alg_wc_pq_product_qty_price_unit', array( $this, 'product_qty_price_unit' ) );
Shortcode PHP function:
function product_qty_price_unit( $atts, $content = '' ) {
return $this->output_shortcode( $this->get_min_or_max_or_step( 'price_unit' ), $atts );
}
Code file location:
product-quantity-for-woocommerce/product-quantity-for-woocommerce/includes/class-alg-wc-pq-shortcodes.php
Min Max Default Quantity for WooCommerce [alg_wc_pq_translate] Shortcode
The ‘alg_wc_pq_translate’ shortcode is a powerful tool that adapts your WooCommerce site to different languages. This shortcode detects the current language of the site. It then outputs text based on the language specified in the shortcode attributes. This allows for dynamic content presentation in multiple languages, enhancing user experience.
Shortcode: [alg_wc_pq_translate]
Parameters
Here is a list of all possible alg_wc_pq_translate shortcode parameters and attributes:
lang
– Defines the language(s) for the displayed textlang_text
– Sets the text to display for specified languagesnot_lang_text
– Sets alternative text for non-specified languagesnot_lang
– Defines the language(s) that should not display the text
Examples and Usage
Basic example – A shortcode that translates the text based on the current language of the website.
[alg_wc_pq_translate lang="EN"]This product is available.[/alg_wc_pq_translate]
Advanced examples
Using the shortcode to display a specific text for English and German languages, and a different text for other languages.
[alg_wc_pq_translate lang="EN,DE" lang_text="This product is available." not_lang_text="This product is not available."][/alg_wc_pq_translate]
Using the shortcode to display a specific message for Dutch language, and a different message for other languages.
[alg_wc_pq_translate lang="NL"]Toegestane hoeveelheid voor %product_title% is %allowed_quantity%.[/alg_wc_pq_translate]
Using the shortcode to display a specific text for English and German languages, and no text for other languages.
[alg_wc_pq_translate lang="EN,DE"]This product is available.[/alg_wc_pq_translate][alg_wc_pq_translate not_lang="EN,DE"][/alg_wc_pq_translate]
PHP Function Code
In case you have difficulties debugging what causing issues with [alg_wc_pq_translate]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'alg_wc_pq_translate', array( $this, 'language_shortcode' ) );
Shortcode PHP function:
function language_shortcode( $atts, $content = '' ) {
$current_language = '';
if (function_exists('pll_current_language')) {
$current_language = strtolower( pll_current_language() );
}
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
$current_language = strtolower( ICL_LANGUAGE_CODE );
}
// E.g.: [alg_wc_pq_translate lang="EN,DE" lang_text="Text for EN & DE" not_lang_text="Text for other languages"]
if ( isset( $atts['lang_text'] ) && isset( $atts['not_lang_text'] ) && ! empty( $atts['lang'] ) ) {
return ( empty( $current_language ) || ! in_array( $current_language, array_map( 'trim', explode( ',', strtolower( $atts['lang'] ) ) ) ) ) ?
$atts['not_lang_text'] : $atts['lang_text'];
}
// [alg_wc_pq_translate lang="DE"]Die zulässige Menge für %product_title% ist %allowed_quantity%.[/alg_wc_pq_translate][alg_wc_pq_translate lang="NL"]Toegestane hoeveelheid voor %product_title% is %allowed_quantity%.[/alg_wc_pq_translate]
if ( ! empty( $atts['lang'] ) && strlen( trim ( $atts['lang'] ) ) == 2) {
if ( strtolower( trim ( $atts['lang'] ) ) == $current_language ) {
return $content;
}
}
// E.g.: [alg_wc_pq_translate lang="EN,DE"]Text for EN & DE[/alg_wc_pq_translate][alg_wc_pq_translate not_lang="EN,DE"]Text for other languages[/alg_wc_pq_translate]
return (
( ! empty( $atts['lang'] ) && ( empty( $current_language ) || ! in_array( $current_language, array_map( 'trim', explode( ',', strtolower( $atts['lang'] ) ) ) ) ) ) ||
( ! empty( $atts['not_lang'] ) && ! empty( $current_language ) && in_array( $current_language , array_map( 'trim', explode( ',', strtolower( $atts['not_lang'] ) ) ) ) )
) ? '' : $content;
}
Code file location:
product-quantity-for-woocommerce/product-quantity-for-woocommerce/includes/class-alg-wc-pq-shortcodes.php
Conclusion
Now that you’ve learned how to embed the Min Max Default Quantity 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.
Leave a Reply