Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter 100cagettes

    (@100cagettes)

    I found this code which is work great, to be perfect, how can i add for product 28, all payement gateway are available except ‘wallet’?

    
    /**
     * @snippet       Disable Payment Method for Specific Category
     * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
     * @sourcecode    https://businessbloomer.com/?p=19892
     * @author        Rodolfo Melogli
     * @compatible    WC 3.5.4
     * @donate $9     https://businessbloomer.com/bloomer-armada/
     */
     
    add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_unset_gateway_by_category' );
     
    function bbloomer_unset_gateway_by_category( $available_gateways ) {
    global $woocommerce;
    $unset = false;
    $category_ids = array( 17, 16, 22 );
    /**
     * Les valeurs 3, 4 et 5 correspondent aux ID des catégories
     */  
    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['stripe'] );
        if ( $unset == true ) unset( $available_gateways['bacs'] );
        return $available_gateways;
    }
Viewing 1 replies (of 1 total)