Coupon Box for WooCommerce Shortcode

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

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

Plugin Icon
Coupon Box for WooCommerce

"Coupon Box for WooCommerce is a versatile plugin that allows WooCommerce store owners to offer enticing deals. It enables easy creation, distribution, and management of coupons, enhancing customer engagement."

★★★★☆ (35) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [wcb_widget]

Coupon Box for WooCommerce [wcb_widget] Shortcode

The Woo-Coupon-Box shortcode is a versatile tool for creating custom coupon widgets. It allows for customization of visibility, button color, background color, button and input border radius, and coupon code display. This shortcode interacts with user login status and cookies to determine widget visibility. It also enqueues necessary scripts and styles, and localizes script data. The shortcode generates a form for users to enter their email and receive a coupon, with GDPR compliance options included.

Shortcode: [wcb_widget]


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

  • type – Defines the design template of the coupon box.
  • always_visible – Determines if the coupon box is always shown.
  • bt_color – Sets the text color of the subscribe button.
  • bt_bg_color – Changes the background color of the subscribe button.
  • bt_border_radius – Adjusts the border radius of the subscribe button.
  • input_border_radius – Modifies the border radius of the email input field.
  • show_coupon_code – Decides if the coupon code is displayed after subscription.

Examples and Usage

Basic example – The shortcode displays the Woo Coupon Box widget with default settings.

[wcb_widget /]

Advanced examples

Display the Woo Coupon Box widget with customized button color and background color.

[wcb_widget bt_color="#ffffff" bt_bg_color="#000000" /]

Display the Woo Coupon Box widget that is always visible, regardless of the user’s login status or previous interactions with the widget.

[wcb_widget always_visible="1" /]

Display the Woo Coupon Box widget with a customized border radius for the button and input field.

[wcb_widget bt_border_radius="10" input_border_radius="5" /]

Display the Woo Coupon Box widget that shows the coupon code immediately after the user subscribes, without requiring a page refresh.

[wcb_widget show_coupon_code="1" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'wcb_widget', array( $this, 'register_shortcode' ) );

Shortcode PHP function:

function register_shortcode( $atts ) {
		extract( shortcode_atts( array(
			'type'                => '1',
			'always_visible'      => '',
			'bt_color'            => '',
			'bt_bg_color'         => '',
			'bt_border_radius'    => '',
			'input_border_radius' => '',
			'show_coupon_code'    => '',
		), $atts ) );
		if ( ! $always_visible ) {
			if ( $this->settings->get_params( 'wcb_disable_login' ) && is_user_logged_in() ) {
				return '';
			if ( isset( $_COOKIE['woo_coupon_box'] ) ) {
				$cookies = explode( ':', sanitize_text_field( wp_unslash( $_COOKIE['woo_coupon_box'] ) ) );
				if ( isset( $cookies[0] ) && in_array( $cookies[0], array( 'subscribed', 'closed' ) ) ) {
					return '';

		if ( ! wp_script_is( 'wcbwidget-shortcode-script' ) ) {
			wp_enqueue_script( 'wcbwidget-shortcode-script' );
			$data = array(
				'ajaxurl'               => admin_url( 'admin-ajax.php' ),
				'wcb_current_time'      => time(),
				'wcb_show_coupon'       => $this->settings->get_params( 'wcb_show_coupon' ),
				'wcb_expire_subscribed' => $this->settings->get_params( 'wcb_expire_subscribed' ) * 86400,
				'wcb_gdpr_checkbox'     => $this->settings->get_params( 'wcb_gdpr_checkbox' ),
			wp_localize_script( 'wcbwidget-shortcode-script', 'wcb_widget_params', $data );
			wp_enqueue_style( 'wcbwidget-shortcode-style' );
			/*button subscribe*/
			$bt_color            = $this->settings->get_params( 'wcb_button_text_color' );
			$bt_bg_color         = $this->settings->get_params( 'wcb_button_bg_color' );
			$bt_border_radius    = $this->settings->get_params( 'wcb_button_border_radius' );
			$input_border_radius = $this->settings->get_params( 'wcb_email_input_border_radius' );
			$css                 = '.woo-coupon-box-widget .wcbwidget-newsletter span.wcbwidget-button{';
			$css                 .= 'color:' . $bt_color . ';';
			$css                 .= 'background-color:' . $bt_bg_color . ';';
			$css                 .= 'border-radius:' . $bt_border_radius . 'px;';
			$css                 .= '}';
			$css                 .= '.woo-coupon-box-widget .wcbwidget-newsletter input.wcbwidget-email{border-radius:' . $input_border_radius . 'px;}';
			wp_add_inline_style( 'wcbwidget-shortcode-style', $css );
        <div class="woo-coupon-box-widget woo-coupon-box-widget-type-<?php echo esc_attr( $type ); ?>">
            <div class="wcbwidget-coupon-box-newsletter">

                <div class="wcbwidget-newsletter">
                    <div class="wcbwidget-warning-message"></div>
                    <div class="wcbwidget-newsletter-form">
                        <div class="wcbwidget-input-group">
                            <input type="email"
                                   placeholder="<?php esc_html_e( 'Enter your email address', 'woo-coupon-box' ) ?>"
                                   class="wcbwidget-form-control wcbwidget-email"

                            <div class="wcbwidget-input-group-btn">
                                <span class="wcbwidget-btn wcbwidget-btn-primary wcbwidget-button" data-show_coupon="<?php echo esc_attr( $show_coupon_code ) ?>">
                                    <?php echo esc_html( $this->settings->get_params( 'wcb_button_text' ) ) ?>
					if ( $this->settings->get_params( 'wcb_gdpr_checkbox' ) ) {
                        <div class="wcbwidget-gdpr-field">
                            <input type="checkbox" name="wcb_gdpr_checkbox" class="wcbwidget-gdpr-checkbox">
                            <span class="wcbwidget-gdpr-message"><?php echo wp_kses_post( $this->settings->get_params( 'wcb_gdpr_message' ) ); ?></span>

		$return = ob_get_clean();
		$return = str_replace( "\n", '', $return );
		$return = str_replace( "\r", '', $return );
		$return = str_replace( "\t", '', $return );
		$return = str_replace( "\l", '', $return );
		$return = str_replace( "\0", '', $return );

		return $return;

Code file location:



Now that you’ve learned how to embed the Coupon Box 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.


Leave a Reply

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