×
Black Friday Savings
00Days
:
06Hours
:
48Minutes
:
37Seconds
Use Coupon 40%OFF

Includes 1 Year Priority Support

Shop Now

WP SITES

3093 Coded Tutorials & 296 Plugins

Make WooCommerce block checkout coupon field open by default

Add this PHP code to your child themes functions file or custom code snippets plugin to make the coupon field open on page load by default.

By default, it’s closed.

add_action( 'wp_enqueue_scripts', 'bd_keep_coupon_field_open_inline', 20 );
function bd_keep_coupon_field_open_inline() {
    if ( is_checkout() ) {
        wp_register_script( 'bd-checkout-inline', '', [], '', true );
        wp_enqueue_script( 'bd-checkout-inline' );

        wp_add_inline_script( 'bd-checkout-inline', "
            jQuery(document).ready(function($) {
                const observer = new MutationObserver(function() {
                    const \$couponButton = $('.wc-block-components-panel__button');
                    if (\$couponButton.length && \$couponButton.attr('aria-expanded') === 'false') {
                        \$couponButton.trigger('click');
                        observer.disconnect();
                    }
                });

                observer.observe(document.body, {
                    childList: true,
                    subtree: true
                });
            });
        " );
    }
}

Related Coded Solutions

Was this helpful?

Yes
No
Thanks for your feedback!

Leave a Reply