• Resolved restalfep

    (@restalfep)


    On the older versions of WooCommerce we didn’t have this issue but on the new versions, it doesn’t show an option to Apply a Coupon on the Checkout page if a coupon is already applied to the order. How can I change this so the customer can still apply a coupon on the Checkout Page even if they already applied one to their site?

    This is very important for us since some coupons can be stacked together (or customers may want to override their current automatic coupon at checkout) and we don’t want to force customers to have to do it on Cart page.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Override this template in your child theme and remove the conditional: https://github.com/woocommerce/woocommerce/blob/master/templates/checkout/form-coupon.php#L27

    Or, to avoid overriding templates, just hook into the woocommerce_before_checkout_form hook with a priority of 9 I believe. And only output that same markup if coupons are applied.

    Thread Starter restalfep

    (@restalfep)

    Thank you for the quick response. I’m completely new to php and coding but learning as I go. Would the following be the right code to use to avoid overriding template file?:

    add_action ( ‘woocommerce_before_checkout_form’, ‘apply_coupon_fieldback’, 9);

    function (apply_coupon_fieldback) {

    global $woocommerce;

    if ( WC()->cart->applied_coupons ) {
    $info_message = apply_filters( ‘woocommerce_checkout_coupon_message’, __( ‘Have a coupon?’, ‘woocommerce’ ) . ‘ ‘ . __( ‘Click here to enter your code’, ‘woocommerce’ ) . ‘‘ );
    wc_print_notice( $info_message, ‘notice’ );

    }

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Looks about right. Couple of notes:

    1) Don’t need to global declaration at the top: global $woocommerce;

    2) function apply_coupon_fieldback() { is how you should start the function out.

    3) if ( ! empty( WC()->cart->applied_coupons ) ) { might be safer.

    4) Probably just from pasting the code in the forums, but double check your quotations marks.

    Thread Starter restalfep

    (@restalfep)

    Thanks!

    Last question, I saw elsewhere something about global $woocommerce being deprecated now, is that true? I only ask because we have a script that automatically applies coupon codes but uses that global declaration so wanted to see if I need to adjust those scripts.

    Thanks again, very helpful!

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    It is a deprecated way of accessing the main WC instance, yes.

    Can just change to WC()->method_name() in all places now instead of $woocommerce->method_name()

    Thread Starter restalfep

    (@restalfep)

    Thanks for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to stop Coupon field from Disappearing on Checkout if coupon applied?’ is closed to new replies.