//DISABLE COD PAYMENT FOR SPECIFIC PRODUCT CATEGORY function unset_payment_cod_for_online_trening( $available_gateways ) { global $woocommerce; $unset = false; $category_ids = array( 109 ); foreach ( $woocommerce->cart->cart_contents as $key => $values ) { $terms = get_the_terms( $values['product_id'], 'product_cat' ); foreach ( $terms as $term ) { if ( in_array( $term->term_id, $category_ids ) ) { $unset = true; break; } } } if ( $unset == true ) unset( $available_gateways['cod'] ); return $available_gateways; } add_action( 'woocommerce_available_payment_gateways', 'unset_payment_cod_for_online_trening', 5 );
Leave a Reply