Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1315792
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have some products categories on my website where customers can collect from my store, so I need to add local pickup as a shipping method. I have added local pickup but it shows a checkbox at the checkout page for customers to select normal shipping or local pickup. What i need is, when a customer adds a products to the cart that is on the "x" category, show them normal shipping cost and local pickup so they can select whichever is convenient for them, and other products only with normal shipping cost. I don't want to show local pickup for other categories.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have some products categories on my website where customers can collect from my store, so I need to add local pickup as a shipping method. I have added local pickup but it shows a checkbox at the checkout page for customers to select normal shipping or local pickup. What i need is, when a customer adds a products to the cart that is on the "x" category, show them normal shipping cost and local pickup so they can select whichever is convenient for them, and other products only with normal shipping cost. I don't want to show local pickup for other categories.
Share Improve this question edited Sep 4, 2019 at 9:08 LoicTheAztec 3,39117 silver badges24 bronze badges asked Sep 4, 2019 at 6:18 AnasAnas 331 silver badge5 bronze badges1 Answer
Reset to default 3The following will only show "Local pickup" shipping method for specific product categories in cart:
add_action( 'woocommerce_package_rates','show_hide_local_pickup_shipping_methods', 10, 2 );
function show_hide_local_pickup_shipping_methods( $rates, $package ) {
// HERE BELOW your product categories in the array
$categories = array( 't-shirts', 'hat' );
$term_found = false;
// Loop through cart items
foreach( $package['contents'] as $cart_item ){
if( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
$term_found = true;
break;
}
}
// Loop through shipping methods
foreach( $rates as $rate_key => $rate ) {
if( 'local_pickup' === $rate->method_id && ! $term_found ) {
unset($rates[$rate_key]);
}
}
return $rates;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Note: You may be need to refresh shipping methods, emptying the cart and going to shipping settings/ then disable / save and re-enable / save any shipping methods.
本文标签: pluginsShow quotLocal Pickupquot shipping method only for specific Woocommerce product categories
版权声明:本文标题:plugins - Show "Local Pickup" shipping method only for specific Woocommerce product categories 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741983894a2408559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论