Cart Notices for WooCommerce Shortcode

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

Before starting, here is an overview of the Cart Notices for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Cart Notices for WooCommerce

"Cart Notices for WooCommerce is an effective tool that helps enhance your e-commerce platform's user experience. It displays custom and dynamic messages based on customers' cart behavior."

★★★★★ (36) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [br_cart_notices]

Cart Notices for WooCommerce [br_cart_notices] Shortcode

The ‘br_cart_notices’ shortcode is part of the Cart Notices for WooCommerce plugin. It generates and displays a list of cart notices on a webpage. This shortcode retrieves a list of notices using the ‘get_notice_list’ function. It then iterates over the list, printing each notice using the ‘wc_print_notice’ function. If no notices are available, it returns an empty string.

Shortcode: [br_cart_notices]

Examples and Usage

Basic Example – The basic usage of the ‘br_cart_notices’ shortcode without any parameters. This will display all the WooCommerce cart notices available.

[br_cart_notices /]

Advanced Examples

Displaying a specific WooCommerce cart notice by its ID. In this case, we are displaying the cart notice with ID 1. This can be useful when you want to display a specific notice based on certain conditions.

[br_cart_notices id=1 /]

Displaying multiple WooCommerce cart notices by their IDs. Here, we are displaying the cart notices with IDs 1 and 2. This can be useful when you want to display a set of specific notices.

[br_cart_notices id="1,2" /]

Using the shortcode to display the WooCommerce cart notices in a custom styled div. The div will have the class ‘my_custom_class’. This can be useful when you want to style the notices differently than the default style.

[br_cart_notices class="my_custom_class" /]
Please note that the ‘id’ and ‘class’ parameters are hypothetical and the actual parameters may vary based on the plugin’s documentation. Always refer to the plugin’s documentation for the correct usage and available parameters of the shortcode.

PHP Function Code

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

Shortcode line:

add_shortcode( 'br_cart_notices', array( $this, 'shortcode' ) );

Shortcode PHP function:

                    function shortcode($atts = array()) {
        $notices_list = $this->get_notice_list();
        ob_start();
        foreach($notices_list as $notice_id => $notice) {
            wc_print_notice('<span class="berocket_cart_notice_shortcode_notice berocket_cart_notice berocket_cart_notice_'.$notice_id.'"></span>'.$notice, 'notice');
        }
        $text = ob_get_clean();
        if( ! empty($text) ) {
            $text = '<div class="woocommerce berocket_cart_notice_shortcode">'.$text.'</div>';
        } else {
            $text = '';
        }
        return $text;
    }
                    

Code file location:

cart-notices-for-woocommerce/cart-notices-for-woocommerce/main.php

Conclusion

Now that you’ve learned how to embed the Cart Notices for 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *