Enable Checkout for only certain products (woocommerce)

[ad_1]

I run a woocommerce site.

Need to turn-on payment option for certain products (not all because they require shipping to be quoted)

Any recommendations as how to set this up?

I've looked in settings and for plugins… google is getting worse with AI suggestions

Many thanks again to this community!

[ad_2]
3 Comments
  1. If you prefer not to use plugins or need more control, you can use a custom code.
    You can add this code to your Theme’s functions.php:

    add_filter(‘woocommerce_available_payment_gateways’, ‘custom_payment_gateway_restriction’);

    function custom_payment_gateway_restriction($available_gateways) {

    if (!is_admin()) {

    // Loop through each product in the cart

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {

    $product = $cart_item[‘data’];

    // Check if the product requires a shipping quote

    if (has_term(‘shipping-quote-required’, ‘product_cat’, $product->get_id())) {

    // Remove specific payment gateways for these products

    unset($available_gateways[‘paypal’]); // Example: Remove PayPal

    }

    }

    }

    return $available_gateways;

    }

    // Replace `’`shipping-quote-required`’` with the actual slug of your category.
    // Modify the `unset` line to match the payment gateways you want to disable (e.g., `’paypal’`).

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer