admin管理员组文章数量:1302384
I try to unset Chash on delivery (unset( $available_gateways['cod'] );
) in specific category.
So i need to get the category id of all product i select it in checkout page woocomerce.
How can do that!
I try to unset Chash on delivery (unset( $available_gateways['cod'] );
) in specific category.
So i need to get the category id of all product i select it in checkout page woocomerce.
How can do that!
Share Improve this question asked Dec 24, 2017 at 10:56 karaazlab karaazlabkaraazlab karaazlab 112 bronze badges 1- to have a custom payement gateway, it's better to create a new one instead of modifying a existing one : docs.woocommerce/document/payment-gateway-api – mmm Commented Dec 24, 2017 at 14:39
1 Answer
Reset to default 1Getting the ids of the items in your cart can be done somewhat like this:
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
foreach ( $cart as $item_key => $item_value ) {
$cart_items_ids[] = $item_value[ 'data' ]->id;
}
OR Plese check below Snippet: Check if Product Category is in the Cart – WooCommerce
add_action('woocommerce_before_cart', 'xyz_check_category_in_cart');
function xyz_check_category_in_cart() {
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
// If Cart has category "download", set $cat_in_cart to true
if ( has_term( 'download', 'product_cat', $product->get_id() ) ) {
$cat_in_cart = true;
break;
}
}
// Do something if category "download" is in the Cart
if ( $cat_in_cart ) {
// For example, print a notice
wc_print_notice( 'Category Downloads is in the Cart!', 'notice' );
// Or maybe run your own function...
}
}
You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it).
Please let me know in the comments if everything worked as expected.
Thank you!
本文标签: woocommerce offtopicGet the category ID in checkout page woocomerce
版权声明:本文标题:woocommerce offtopic - Get the category ID in checkout page woocomerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741690954a2392719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论