1. Overview
This document explains how to modify payment methods at checkout based on product type in WooCommerce. Specifically:
- If the cart contains downloadable products, only online payment methods (e.g., PayPal, Stripe) will be displayed, and Cash on Delivery (COD) will be hidden.
- If the cart contains only non-downloadable products, only COD will be displayed, and other payment methods will be hidden.
This solution uses custom PHP code snippets that hook into WooCommerce’s payment gateway system.
2. Prerequisites
- A WordPress website with WooCommerce installed.
- Access to the site’s
functions.php
file (preferably via a child theme) or a custom plugin. - Basic understanding of WordPress hooks and PHP.