Woo Discount Rules Shortcodes

Below, you’ll find a detailed guide on how to add the Woo Discount Rules 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 Woo Discount Rules Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Woo Discount Rules Plugin and the shortcodes it provides:

Plugin Icon
Discount Rules for WooCommerce – Create Smart WooCommerce Coupons & Discounts

"Discount Rules for WooCommerce is a smart plugin that enables you to create tailored WooCommerce coupons & discounts. Its slug is 'woo-discount-rules', simplifying coupon creation & management."

★★★★☆ (744) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [awdr_sale_items_list]
  • [awdr_banner_content]

Woo Discount Rules [awdr_sale_items_list] Shortcode

The ‘awdr_sale_items_list’ shortcode from Woo Discount Rules plugin displays a list of products on sale. It allows customization of product display, such as the number of products per page, column count, sorting order, and pagination.

Shortcode: [awdr_sale_items_list]

Parameters

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

  • per_page – Defines the number of products displayed per page
  • columns – Determines the number of product columns on a page
  • orderby – Sets the product sorting parameter
  • do_pagination – Enables or disables pagination
  • order – Specifies the product sorting order (ascending or descending)

Examples and Usage

Basic example – Display a list of sale items with default settings.

[awdr_sale_items_list]

Advanced examples

Display a list of sale items, specifying the number of items per page, the number of columns, the order of items, and whether pagination is enabled.

[awdr_sale_items_list per_page="10" columns="4" orderby="date" do_pagination="1" order="desc"]

Display a list of sale items, specifying the number of items per page and the order of items, but with no pagination and a single column layout.

[awdr_sale_items_list per_page="20" columns="1" orderby="title" do_pagination="0" order="asc"]

Note: In the above examples, ‘per_page’ attribute is used to define the number of items to display per page, ‘columns’ attribute is used to define the number of columns, ‘orderby’ attribute is used to define the order of items (it can be ‘title’, ‘date’, etc.), ‘do_pagination’ attribute is used to enable or disable pagination (1 for enable and 0 for disable), and ‘order’ attribute is used to define the order of items (it can be ‘asc’ for ascending order and ‘desc’ for descending order).

PHP Function Code

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

Shortcode line:

add_shortcode('awdr_sale_items_list', array(self::$short_code_manager, 'saleItemsList'));

Shortcode PHP function:

function saleItemsList($short_code_attributes)
    {
        if (!empty(self::$available_rules)) {
            global $woocommerce_loop;
            $short_code_attributes = shortcode_atts(array(
                'per_page' => 12,
                'columns' => 3,
                'orderby' => 'title',
                'do_pagination' => 1,
                'order' => 'asc'
            ), $short_code_attributes);
            $paged = $this->input->get('product-page', 1);
            $order_by = $this->input->get('orderby', 'title');

            ob_start();
            $onsale_list = OnSaleShortCode::getOnSaleList();
            if(!empty($onsale_list)){
                $query_arguments = array(
                    'post_type' => 'product',
                    'post_status' => 'publish',
                    'paged' => $paged,
                    'posts_per_page' => $short_code_attributes['per_page'],
                    'orderby' => $short_code_attributes['orderby'],
                    'order' => $short_code_attributes['order'],
                );
                if($onsale_list['has_store_wide']){
                    if (!empty($onsale_list['list'])) {
                        $query_arguments['post__not_in'] = $onsale_list['list'];
                    }
                } else {
                    if (!empty($onsale_list['list'])) {
                        $query_arguments['post__in'] = $onsale_list['list'];
                    }
                }
                // Exclude_out_of_stock_products_for_on_sale_page
                $exclude_out_of_stock_products_for_on_sale_page = self::$config->getConfig('exclude_out_of_stock_products_for_on_sale_page', apply_filters('advanced_woo_discount_rules_exclude_out_of_stock_product_on_sale_page', 0));
                if(!empty($exclude_out_of_stock_products_for_on_sale_page)){
                    $exclude_out_of_stock = array('meta_query' => array(
                        array(
                            'key' => '_stock_status',
                            'value' => 'instock'
                        ),
                        array(
                            'key' => '_backorders',
                            'value' => 'no'
                        ),
                    ));
                    $query_arguments = array_merge($query_arguments, $exclude_out_of_stock);
                }
            } else {
                $query_arguments = array();
            }
            $products = new \WP_Query($query_arguments);
            $columns = absint($short_code_attributes['columns']);
            $woocommerce_loop['columns'] = $columns;
            if ($products->have_posts()) {
                self::$woocommerce_helper->setLoopProperties('is_shortcode', true);
                self::$woocommerce_helper->setLoopProperties('is_paginated', (!empty($short_code_attributes['do_pagination'])));
                self::$woocommerce_helper->setLoopProperties('per_page', $short_code_attributes['per_page']);
                self::$woocommerce_helper->setLoopProperties('current_page', $paged);
                $total = $products->found_posts;
                self::$woocommerce_helper->setLoopProperties('total', $total);
                $total_pages = ceil($total / $short_code_attributes['per_page']);
                self::$woocommerce_helper->setLoopProperties('total_pages', $total_pages);
                do_action('woocommerce_before_shop_loop');
                self::$woocommerce_helper->productLoopStart();
                while ($products->have_posts()) {
                    $products->the_post();
                    wc_get_template_part('content', 'product');
                }
                self::$woocommerce_helper->productLoopEnd();
                do_action('woocommerce_after_shop_loop');
                // woocommerce_pagination();
                wp_reset_postdata();
            } else {
                do_action('woocommerce_no_products_found');
            }
            return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
        }
        return NULL;
    }

Code file location:

woo-discount-rules/woo-discount-rules/v2/App/Router.php

Woo Discount Rules [awdr_banner_content] Shortcode

The woo-discount-rules plugin shortcode, ‘awdr_banner_content’, is designed to display customized banner content. It fetches content from the plugin’s configuration and outputs it in a designated HTML div. If no content is set, it displays a default message, ‘No Banner Content’. This ensures the banner area is never left blank.

Shortcode: [awdr_banner_content]

Examples and Usage

Basic example – Utilizing the shortcode to display a default banner content using the ‘awdr_banner_content’ shortcode.

[awdr_banner_content /]

For advanced examples:

Advanced example – Displaying the banner content by referencing the ID. If the banner content with the specified ID is not found, it will display a message ‘No Banner Content’.

[awdr_banner_content id=2 /]

Advanced example – Utilizing the shortcode to display a banner content by referencing both ID and title. The banner content will first try to load by ID, but if not found, it will try to load by title.

[awdr_banner_content id=2 title='Summer Sale' /]

Please note: The above examples are hypothetical and may not work as expected as the actual functionality of the shortcode depends on how it’s been defined in the plugin code. Make sure to replace the id and title with the actual values that you have in your WordPress setup.

PHP Function Code

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

Shortcode line:

add_shortcode('awdr_banner_content', array(self::$short_code_manager, 'bannerContent'));*/

Shortcode PHP function:

function bannerContent(){
        echo "";
        /*$awdr_banner_editer = self::$config->getConfig('awdr_banner_editor', '');
        if(!empty($awdr_banner_editer) && $awdr_banner_editer != ''){
            $awdr_banner_editer = $this->getCleanHtml($awdr_banner_editer);
            echo "<div class='awdr_banner_content'>".$awdr_banner_editer."</div>";
        }else{
            echo "<div class='awdr_banner_content'>"._e('No Banner Content', 'woo-discount-rules');".</div>";
        }*/
    }

Code file location:

woo-discount-rules/woo-discount-rules/v2/App/Router.php

Conclusion

Now that you’ve learned how to embed the Woo Discount Rules 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 *