• Resolved restalfep

    (@restalfep)


    Before the latest update your support had told us to add the following to our functions.php to prevent the coupon field from disappearing:

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

    function apply_coupon_fieldback() {

    if ( ! empty( WC()->cart->applied_coupons ) ) {
    $info_message = apply_filters( ‘woocommerce_checkout_coupon_message’, __( ‘Have a coupon?’, ‘woocommerce’ ) );

    wc_print_notice( $info_message, ‘notice’ );

    }
    }

    This code was working great until the latest update. Now it doesn’t work and our checkout page won’t expand the “Click here” next to the coupon section if a coupon is already applied. If no coupon is applied then it will expand to show the box to enter a coupon. Any ideas what changed and how to fix this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    I’d just like to catch up on the run-up to this forum thread – could you send through the ticket number or forum thread URL to see where this was suggested?

    Thanks!

    Thread Starter restalfep

    (@restalfep)

    Plugin Support Ryan Ray, a11n

    (@ryanr14)

    Hi there,

    Here is what’s worked for me, with an explanation of what I think went wrong in the initial snippet you had. ??

    
    function apply_coupon_fieldback() {
    
    	if ( ! empty( WC()->cart->applied_coupons ) ) { ?>
    
    		<div class="woocommerce-form-coupon-toggle">
    			<?php wc_print_notice( apply_filters( 'woocommerce_checkout_coupon_message', __( 'Have a coupon?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>' ), 'notice' ); ?>
    		</div>
    
    			<form class="checkout_coupon woocommerce-form-coupon" method="post" style="display:none">
    
    				<p><?php esc_html_e( 'If you have a coupon code, please apply it below.', 'woocommerce' ); ?></p>
    
    				<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">
    					<button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button>
    				</p>
    
    				<div class="clear"></div>
    			</form>
    			<?php
    	}
    }
    
    add_action ( 'woocommerce_before_checkout_form', 'apply_coupon_fieldback', 9);
    

    Originally when I pasted your first snippet into my editor I needed to replace what looked like curly quotes with straight quotes. Maybe the editor you are using automatically does that if it is more suited to word processing? See here for more explanations on that.

    I also just did a little re-arranging and updating to the code used. In particular, using Storefront it worked better, in my opinion, to place this above the checkout form so I used woocommerce_before_checkout_form.

    I also got your notice to appear, but it didn’t include a link that would open the form nor the actual form code. I’ve copied that over into the new snippet above. Let me know if that is helpful!

    Here is a quick video so you can see what I see.

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