• Resolved shwetaarya

    (@shwetaarya)


    Hello Team,

    In Woocommerce, I want to hide the COD (Cash on Delivery) payment option if a specific product variation is in the cart. Please help.

    This is what I am currently using:

    add_filter(‘woocommerce_available_payment_gateways’, ‘conditional_payment_gateways’, 10, 1);
    function conditional_payment_gateways( $available_gateways ) {
    $in_cart = false;
    foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
    // See if there is an attribute called ‘pa_size’ in the cart
    // Replace with whatever attribute you want
    if (array_key_exists(‘personalization-required’, (array) $values[‘data’]->get_attributes() ) ) {
    foreach ($values[‘data’]->get_attributes() as $attribute => $variation);
    // Replace ‘small’ with your value.
    if ($variation == ‘Yes’) $in_cart = true; //edited
    }
    }
    if ( $in_cart )
    unset($available_gateways[‘cod’]); // unset ‘cod’

    return $available_gateways;
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide payment method if specific variation is in Checkout Page’ is closed to new replies.