Below, you’ll find a detailed guide on how to add the Combo Offers 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 Combo Offers WooCommerce Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Combo Offers WooCommerce Plugin and the shortcodes it provides:
"Combo Offers WooCommerce is a dynamic plugin for WordPress that enables you to create enticing product bundles and special offers, enhancing your WooCommerce store's profitability."
- [wooco_list_products]
Combo Offers WooCommerce [wooco_list_products] Shortcode
The ‘wooco_list_products’ shortcode from the Woo-Combo-Offers plugin fetches and displays all published products of the ‘wooco’ type. It allows customizing the number of columns. If no column number is provided, it defaults to 3. The products are then displayed via the ‘products’ shortcode, utilizing the fetched product IDs.
Shortcode: [wooco_list_products]
Parameters
Here is a list of all possible wooco_list_products shortcode parameters and attributes:
columns
– determines the number of product columns to display
Examples and Usage
Basic example – The basic usage of the ‘wooco_list_products’ shortcode does not require any additional parameters. It will simply list all of the products of the ‘wooco’ product type that are currently published on your WordPress site.
[wooco_list_products]
Advanced examples
Customizing the number of columns – You can customize the number of columns in which the products are displayed by adding the ‘columns’ parameter to the shortcode. The following example will display the products in 4 columns.
[wooco_list_products columns=4]
Combining parameters – It’s also possible to combine parameters for more advanced usage. For instance, you can specify both the ‘columns’ and ‘posts_per_page’ parameters to control both the layout and the number of products displayed. Note that ‘posts_per_page’ parameter is not directly used in the shortcode but you can modify it in the function ‘wooco_list_products’ in your functions.php file. Here’s how you might do that:
function wooco_list_products( $atts ) {
global $wpdb;
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => isset($atts['posts_per_page']) ? $atts['posts_per_page'] : -1,
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'wooco'
)
),
'fields' => 'ids'
);
// Rest of the function...
}
Then you can use the shortcode like this:
[wooco_list_products columns=4 posts_per_page=10]
PHP Function Code
In case you have difficulties debugging what causing issues with [wooco_list_products]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wooco_list_products', array($this, 'wooco_list_products'), 10, 1);
Shortcode PHP function:
function wooco_list_products( $atts ) {
global $wpdb;
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'wooco'
)
),
'fields' => 'ids'
);
$the_query = new WP_Query( $args );
if(isset($atts['columns']) &&!empty($atts['columns'])) {
$columns = $atts['columns'];
} else {
$columns = 3;
}
if(isset($the_query->posts) && !empty($the_query->posts) && is_array($the_query->posts)) {
$str_ids = implode(',', $the_query->posts);
ob_start();
echo do_shortcode("[products ids=" . $str_ids . " columns=" . $columns . "]");
return ob_get_clean();
}
return '';
}
Code file location:
woo-combo-offers/woo-combo-offers/woo-combo-offers.php
Conclusion
Now that you’ve learned how to embed the Combo Offers 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.
Leave a Reply