Reputation: 1336
In WooCommerce > Settings > Shipping > Shipping Zones > (the shipping zone) > flat rate, there are the inputs where you can put in custom shipping costs for shipping classes. In here, we can already use [qty] to finetune the results. Is there a way we can customize this to allow for custom shortcodes?
Say for example:
[qty] * 5 * [jwd_free_shipping_a]
Where jwd_free_shipping_a
is a shortcode that checks to see if the entire pre-tax total of the cart is greater than, say, $100. If yes, it returns 0 (which would make it free shipping for this item in the above calculation), otherwise is returns 1.
Upvotes: 1
Views: 143
Reputation: 1336
Oops, silly me, it looks like you already can use shortcodes there!
This is very helpful for setting up custom shipping rules!
Note: You can also pass [cost]
in as a shortcode parameter, which returns the cost of the item in the cart, not the entire cost of the cart.
In my case, I ended up creating the shortcode as follows. Returning either a 1 or 0 helps me to potentially return free shipping based on a math equation I use (not the same one in the original post, but somewhat similar). I haven't seen any mention of this tactic in my search of Stack Overflow, so I'll leave this here as a reference.
add_shortcode('jwd_custom_shipping_a', 'jwd_custom_shipping_a_shortcode');
function jwd_custom_shipping_a_shortcode() {
$return = 1;
$cart_subtotal = WC()->cart->subtotal;
if ($cart_subtotal > 89) {
$return = 0;
}
return $return;
}
Upvotes: 0