php - 在 PHP 函数 WooCommerce 中运行 CSS
问题描述
我写了这个函数:
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,我该怎么做?
解决方案
基于:从 php if 语句运行 JavaScript 函数(我建议您先阅读已接受的答案和@treyBake 的评论)
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>";
}
}
}
希望这可以帮助。
推荐阅读
- continuous-integration - How to build a ci / cd pipeline with hybris commerce?
- swift - Custom init with @Namespace for .matchedGeometryEffect
- microsoft-graph-api - The method openShiftsRequests return Resource not found for the segment 'openShiftsRequests'
- python - Faster Way to Lookup Values in Numpy Structured Array
- python - Error setting up MNN module in a Raspberry pi 4 "dynamic module does not define module export function (PyInit_libMNN)"
- google-cloud-platform - Cross GSuite Organizations Domain-Wide Delegation
- c# - 如何使用自定义格式向 DateTime 变量添加天数
- javascript - 如何让控制台输出我的号码?
- java - 在 Java dropwizard 微服务上使用 jaeger 启用跟踪
- bpmn - Petri 网到 BPMN