Woocommerce-在单个订单中禁用可下载产品和其他产品
我希望停止在购物车/订单中混合不同类型的产品 用例-可下载的非虚拟产品不应与单个购物车/订单中的任何其他产品一起使用 谢谢你的帮助 重复:Woocommerce-在单个订单中禁用可下载产品和其他产品,woocommerce,hook-woocommerce,Woocommerce,Hook Woocommerce,我希望停止在购物车/订单中混合不同类型的产品 用例-可下载的非虚拟产品不应与单个购物车/订单中的任何其他产品一起使用 谢谢你的帮助 重复: add_filter( 'woocommerce_add_to_cart_validation', 'remove_all_other_if_individual' ); function remove_all_other_if_individual( $cart_item_data ) { global $woocomme
add_filter( 'woocommerce_add_to_cart_validation', 'remove_all_other_if_individual' );
function remove_all_other_if_individual( $cart_item_data ) {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$is_downloadable_incart = false;
foreach ( $items as $item => $values ) {
$_product = wc_get_product( $values[ 'data' ]->get_id() );
if ( $_product->is_downloadable() )
$is_downloadable_incart = TRUE;
}
if ( $is_downloadable_incart )
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return true;
}