-2

I wrote this function:

add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
function adding_custom_price( $cart ) {
global $woocommerce;

    foreach ( $cart->get_cart() as $cart_item ) {

        //If there is minimum 1 coupon active
        if (!empty(WC()->cart->applied_coupons)) {

        }
        //If there isn't any coupon in cart
        else {
          //Here I want to do some styling in CSS or run something in jQuery
        }
    }
}

I want to do some CSS in it and run some jQuery in the else, how can I do that?

PHCoder
  • 1
  • 5

1 Answers1

0

Based on: Run a JavaScript function from a php if statement (I recommend you to read the accepted answer of this and @treyBake's comment first)

add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
function adding_custom_price( $cart ) {
    global $woocommerce;
    foreach ( $cart->get_cart() as $cart_item ) {

        //If there is minimum 1 coupon active
        if (!empty(WC()->cart->applied_coupons)) {

        }
        //If there isn't any coupon in cart
        else {
        //Here I want to do some styling in CSS or run something in jQuery
        echo "<script>function myFunction() {var x = document.getElementsByClassName('checkout-button'); x[0].innerHTML = 'Checkout with no Coupons';}</script>";
        }
    }
}

Hope this helps.

MrEbabi
  • 740
  • 5
  • 16