-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?

1
  • You can not run CSS / JQuery inside PHP code. Commented Nov 29, 2019 at 9:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.