I’d like to do per product shipping programmatically. And I don’t want to use the plugin. This seems like it would easy:
- add meta field called “shipping_price” for each product.
- hook into checkout and update shipping based off each products “shipping_price” that’s in your cart
I know how to do #1. but any ideas on the best way to achieve #2?
2
Answers
Expanding on 7uc1f3rs answer. I had to slightly modify to get it to work with WooCommerce 3.0+ new way of doing it.
needs to be
You can use functions from https://docs.woocommerce.com/wc-apidocs/class-WC_Shipping_Rate.html for $rates
This can be done in the following way, using
get_post_meta
to get the meta field'shipping_price'
Note 1: to test this code added a line with dummy data
Note 2: Don’t forget to specify the
$rate->method_id