脚本宝典收集整理的这篇文章主要介绍了php – 基于特定产品类别的WooCommerce结帐消息,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我添加了一条自定义消息,该消息现在显示在“下订单”按钮下方.
然而,无论购物车中是什么,它都会出现.
这是我目前的代码:
add_action( 'woocommerce_after_checkout_form','allclean_add_checkout_content',12 ); function allclean_add_checkout_content() { echo '<div class="checkoutdisc">Custom message apPEars here fine.</div>'; }
是否有一个简单的代码可以在此行之前添加,这使得它仅适用于购物车中某个类别的产品?
谢谢
这是代码:
add_action( 'woocommerce_after_checkout_form',12 ); function allclean_add_checkout_content() { // set your special category name,slug or ID here: $special_cat = 'special_category'; $bool = false; foreach ( WC()->cart->get_cart() as $cart_ITem_key => $cart_item ) { $item = $cart_item['data']; if ( has_term( $special_cat,'PRoduct_cat',$item->id ) ) $bool = true; } // If the special cat is detected in one items of the cart // It displays the message if ($bool) echo '<div class="checkoutdisc">This is Your custom message displayed.</div>'; }
add_action( 'woocommerce_after_checkout_form',12 ); function allclean_add_checkout_content() { // set your products IDs here: $product_ids = array( 31,68,87,124); $bool = false; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $item = $cart_item['data']; if ( in_array( $item->id,$product_ids ) ) $bool = true; } // If the special cat is detected in one items of the cart // It displays the message if ($bool) echo '<div class="checkoutdisc">This is Your custom message displayed.</div>'; }
此代码位于活动子主题(或主题)的function.PHP文件中,或者也可以放在任何插件文件中.
此代码经过测试和运行.
以上是脚本宝典为你收集整理的php – 基于特定产品类别的WooCommerce结帐消息全部内容,希望文章能够帮你解决php – 基于特定产品类别的WooCommerce结帐消息所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。