developerme
developerme

Reputation: 1955

Hide Coupon notice form in Woocommerce checkout page

On my website the checkout page containing "Have a coupon? Click here to enter your code" box. I don't want this field on checkout page.I applying coupon via URl. I want to remove this box from checkout page by CSS. I attached the screenshot of that box in my checkout page. enter image description here

Is this possible?

I have already tried this:

function hide_coupon_field_on_checkout( $enabled ) {
    if ( is_checkout() ) {
        $enabled = false;
    }
    return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_checkout' );

But it disable coupons functionality in checkout page.

Any help will be appreciated.

Upvotes: 2

Views: 9572

Answers (3)

LoicTheAztec
LoicTheAztec

Reputation: 254492

You can use a custom function hooked in woocommerce_before_checkout_form action hook that will remove the notice coupon form without disabling coupon functionality in checkout page:

add_action( 'woocommerce_before_checkout_form', 'remove_checkout_coupon_form', 9 );
function remove_checkout_coupon_form(){
    remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works.

Upvotes: 10

Gustavo Edinger
Gustavo Edinger

Reputation: 59

You can override the coupon template file at wp-content/themes/yourtheme/woocommerce/checkout/form-coupon.php and comment wc_print_notice and set display of the form to none.

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

if ( ! wc_coupons_enabled() ) {
    return;
}

if ( empty( WC()->cart->applied_coupons ) ) {
    $info_message = apply_filters( 'woocommerce_checkout_coupon_message', __( 'Have a coupon?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>' );
    //wc_print_notice( $info_message, 'notice' );
}
?>

<form class="checkout_coupon" method="post" style="display:none">

    <p class="form-row form-row-first">
        <input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
    </p>

    <p class="form-row form-row-last">
        <input type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>" />
    </p>

    <div class="clear"></div>
</form>

Upvotes: 1

Eliellel
Eliellel

Reputation: 1446

This tag seems not having an unique id/class assigned. But something like this should be able to do it:

$(".showcoupon").closest(".woocommerce-info").hide();  

Upvotes: 2

Related Questions