根据Woocommerce中的延期交货项目显示隐藏支付网关

I'm need to hide paypal when there's any backordered item on cart or hide cod if there's not any item to be backordered. My problem here is if there's a item that's backorder together with one that is not, I end up whitout a payment processor

 add_filter( 'woocommerce_available_payment_gateways', 'backordered_items_hide_cod', 90, 1 );
function backordered_items_hide_cod( $available_gateways ) {
    // Only on front end
    if ( is_admin() )
        return;

    // Loop through cart items
    foreach( WC()->cart->get_cart() as $cart_item ){
        if( $cart_item['data']->is_on_backorder( $cart_item['quantity'] ) ) {
            // Hide payment gateway
            unset($available_gateways['paypal']);
            } else {
            unset($available_gateways['cod']);
            break; // Stop the loop
        }
    }

    return $available_gateways;
}

The following function will hide paypal for any backordered item found or if there is no backordered items it will hide COD instead:

add_filter( 'woocommerce_available_payment_gateways', 'backordered_items_hide_cod', 90, 1 );
function backordered_items_hide_cod( $available_gateways ) {
    // Only on front end
    if ( is_admin() )
        return;

    $has_a_backorder = false;

    // Loop through cart items
    foreach( WC()->cart->get_cart() as $cart_item ){
        if( $cart_item['data']->is_on_backorder( $cart_item['quantity'] ) ) {
            $has_a_backorder = true;
            break;
        } 
    }

    if( $has_a_backorder ) {
        unset($available_gateways['paypal']);
    } else {
        unset($available_gateways['cod']);
    }

    return $available_gateways;
}

Code goes in function.php file of your active child theme (active theme). Tested and works.