Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP函数中运行CSS_Php_Jquery_Css_Wordpress_Woocommerce - Fatal编程技术网

在PHP函数中运行CSS

在PHP函数中运行CSS,php,jquery,css,wordpress,woocommerce,Php,Jquery,Css,Wordpress,Woocommerce,我写了这个函数: 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 acti

我写了这个函数:

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
        }
    }
}
我想在它里面做一些CSS,在else里运行一些jQuery,我该怎么做呢?

基于:(我建议你先阅读这篇文章的公认答案和@treyBake的评论)

add_动作('woocommerce_前计算_总数','add_自定义_价格',10,1);
添加自定义价格($cart)的函数{
全球商业;
foreach($cart->get\u cart()作为$cart\u项目){
//如果至少有1张优惠券有效
如果(!空(WC()->cart->applicated_优惠券)){
}
//如果购物车里没有任何优惠券
否则{
//在这里,我想用CSS做一些样式,或者在jQuery中运行一些东西
echo“function myFunction(){var x=document.getElementsByClassName('checkout-button');x[0]。innerHTML='checkout with no-couples';}”;
}
}
}

希望这有帮助。

您不能在PHP代码中运行CSS/JQuery。
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>";
        }
    }
}