简体   繁体   中英

Modify php snippet to exclude two terms instead of just one?

I am working from the following snippet, which works great, I've made it include more arrays, and have changed which 'available_gateway' is excluded, but I'm having difficulty getting two different gateways to be 'unset' for the same array. Here's the original snippet:

add_filter('woocommerce_available_payment_gateways',
           'bbloomer_unset_gateway_by_category');

function bbloomer_unset_gateway_by_category($available_gateways){
    global $woocommerce;
    $category_IDs = array(316,317);
    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( $available_gateways['cod'] );
                break;
            }
            break;

        }

    }
    return $available_gateways;
}

I would like to also "unset" the 'cheque' payment gateway, I have managed to unset 'cod' or 'cheque' for differing arrays, but not both for one array - thoughts?

THANK YOU!!!

您可以一次取消设置多个变量。

unset($var1, $var2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM