在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>";
}
}
}