Setting up different delivery options for specific products in WooCommerce involves using conditional logic to control shipping methods based on the products in the cart. Here’s a step-by-step guide on how to offer shipping for one product and local pickup only for another within WooCommerce:
Step 1: Set Up Shipping Zones
First, you need to configure your shipping zones and methods in WooCommerce:
- Go to WooCommerce > Settings > Shipping in your WordPress dashboard.
- Add a Shipping Zone and name it (e.g., “Domestic” for local shipping).
- Add Shipping Methods to this zone. You’ll likely want to add both ‘Flat Rate’ and ‘Local Pickup’. You can configure these based on your needs.
Step 2: Install a Plugin for Conditional Shipping
Since WooCommerce by default doesn’t allow you to disable shipping methods based on specific products directly, you’ll need a plugin that can handle conditional logic for shipping. Here are a couple of popular options:
- WooCommerce Conditional Shipping and Payments: This plugin allows you to create conditions for shipping methods and payment gateways based on various factors, including product, category, cart subtotal, and more.
- Table Rate Shipping by WooCommerce (if you need more detailed shipping rules based on weight, items, etc.).
Step 3: Configure the Plugin
Once you have installed your chosen plugin, configure it to set up conditions for your products:
Using WooCommerce Conditional Shipping and Payments
- Go to WooCommerce > Settings > Conditional Shipping and Payments.
- Add a New Condition. Here, you can specify conditions such as:
- If Product A is in the cart, enable ‘Flat Rate’.
- If Product B is in the cart, disable ‘Flat Rate’ and enable only ‘Local Pickup’.
Step 4: Test Your Setup
- Add Product A to the cart and check if both shipping and pickup options are available.
- Add Product B to the cart and check if only the local pickup is available.
Make sure to test various combinations of products to ensure that the conditions work as expected. Testing in a staging environment before going live is also a good practice to avoid disrupting your live store.
Optional: Customize Further with Code
If you’re comfortable with coding or have access to a developer, you can also achieve this functionality by adding custom functions to your theme’s functions.php file. This method requires a good understanding of PHP and WooCommerce hooks.
Here’s a basic example of how you might code this:
function custom_override_shipping_methods($available_methods) { global $woocommerce; $specific_product_id = 123; // ID of the product that should only have local pickup // Check if the specific product is in the cart foreach($woocommerce->cart->cart_contents as $key => $values) { if($values['product_id'] == $specific_product_id) { // Remove all methods except local pickup foreach($available_methods as $method_id => $method) { if($method_id !== 'local_pickup:1') { // Ensure the correct ID for local pickup unset($available_methods[$method_id]); } } break; } } return $available_methods; } add_filter('woocommerce_package_rates', 'custom_override_shipping_methods', 100);
This code checks if a specific product is in the cart and, if so, removes all shipping methods except local pickup.
Final Thoughts
Using a plugin is the easiest and most flexible approach for most users, especially those who prefer not to edit code. If your needs grow more complex, consider hiring a developer to customize your WooCommerce store to precisely match your business requirements.
Recent Comments