myCRED block pay for an order in all categories, except in one

can anyone help to modify these code? I want to block the option to pay for an order in WooCommerce using points in ALL categories , except in one…

Hier is the original code-snippet:
/**
* Block Point Checkouts
* Block the option to pay with myCRED points if a product in our cart
* is in our “blocked” product category.
* @version 1.0
*/
function mycred_pro_block_point_checkouts( $gateways ) {

// If myCRED is not available there is no need for us to do anything
if ( ! array_key_exists( ‘mycred’, $gateways ) ) return $gateways;

global $woocommerce;

// The product category term ID to block
$block_category = 1272;

// Get the carts content
$content = $woocommerce->cart->get_cart();
if ( ! empty( $content ) ) {
foreach ( $content as $item ) {

$product_id = absint( $item[‘product_id’] );

// Get the category(s) the product is in
$categories = wp_get_post_terms( $product_id, ‘product_cat’, array( ‘fields’ => ‘ids’ ) );

// If the product is in the block category we remove myCRED as a payment option
if ( ! empty( $categories ) && in_array( $block_category, $categories ) )
unset( $gateways[‘mycred’] );

}
}

return $gateways;

}
add_filter( ‘woocommerce_available_payment_gateways’, ‘mycred_pro_block_point_checkouts’, 90 );

Read more here:: myCRED block pay for an order in all categories, except in one

Leave a Reply

Your email address will not be published. Required fields are marked *