Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Force DIV refresh upon coupon X application / removal WordPress

  • SOLVED

Hi

WC checkout page contains a DIV.
How can I force a single (ajax) refresh of the DIV any time coupon X (a specific coupon name) is being applied or removed?

Answers (1)

2018-04-22

Francisco Javier Carazo Gil answers:

How do you want to do the DIV refresh?


User179884 comments:

Based on an event handler that is produced anytime coupon "X" is applied or removed. That means that the application or removal of a specific coupon (named "X") will result in a specific DIV refresh. Tnx.


Francisco Javier Carazo Gil comments:

add_action( 'woocommerce_applied_coupon', 'cod_woocommerce_applied_coupon', 10, 1 );
function cod_woocommerce_applied_coupon( $coupon_code ){
if( $coupon_code == 'MY_COUPON_CODE' ){
?>
<script>
jQuery( document ).ready( function( $ ){
$( '#mydiv' ).refresh();
} )
</script>
<?php
}
}


User179884 comments:

Hi. How to I trigger a DIV refresh when that specific coupon is removed ?
I need to trigger a refresh both on application and removal of a specific coupon. Tnx


User179884 comments:

So far the code provide does not work. I get the following fatal error:

Uncaught TypeError: $(...).refresh is not a function


Francisco Javier Carazo Gil comments:

As I told you, what is refresh? And I have inserted the code "refresh". You have to change this function with the code you have done to refresh (you haven't told how this div is refreshed and with your info this is not possible to tell you how to refresh anything).

You can use the hook woocommerce_removed_coupon to make the same code to make this possible when a coupon is removed.