add_filter( 'woocommerce_available_payment_gateways', 'wbmz_indrie_uitzetten_custom_field' );
function wbmz_indrie_uitzetten_custom_field( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( ! is_checkout() ) return $available_gateways;
$inbetalen = array();
foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
$in_drie = get_field('in3',$values['product_id']);
if($in_drie):
$inbetalen[] = 1;
else:
$inbetalen[] = 0;
endif;
}
if (!in_array("1", $inbetalen)) {
unset( $available_gateways['pay_gateway_capayablegespreid'] );
};
return $available_gateways;
}
Origineel
add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_unset_gateway_by_category' );
function bbloomer_unset_gateway_by_category( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( ! is_checkout() ) return $available_gateways;
$unset = false;
$category_ids = array( 8, 37 );
foreach ( WC()->cart->get_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['cheque'] );
return $available_gateways;
}
#betaalmethode #cart #conditional #functions #WC #woocommerce