I'm trying to make a custom page on Wordpress that display 2 subscription types in a form with 3 variations each (monthly, 6 month, 12 month). Each variation gets a radio button and I have a total price that is live updated when user clicks on the radio buttons. This part is working.
But now, I want to add 3 other radio buttons to choose the shipment method. (When user select one, it'll live update the total price too).
I've been searching a long time how to get shipping cost for a product but nothing has worked.
Anyone knows :) ?
This question is too broad. So I can answer partially as you should need to make some work yourself, and ask later more specific questions…
1) Customer location (for shipping Zones):
You should need to get the customer location or shipping zone first.
Then you will need to update the customer country in
WC()->session
and inWC()->customer
objects. This can be done with the following:2) The shipping methods (by Shipping Zone, with costs):
In Woocommerce the Shipping methods for a Shipping Zone are only available when customer add a product to cart…
Based on this answer code: Display shipping methods to frontend as in the admin panel?
we can make a custom array of the necessary data to be used to get the shipping methods by shipping Zones, with costs and everything needed.
The code below is much more complete and include the shipping methods costs:
3) Product page
Customer location:
You will need first to have a location selector (to define the Shipping Zone) or to set the location based on Woocommerce geolocation.
Shipping Methods:
Once the Shipping Zone is defined, you can get the corresponding Shipping Methods and rates (costs), displaying on this product page your radio buttons for Shipping methods.
To get this, you should need to alter the single product pages:
WC_Session
andWC_Customer
).You should need to get/set/update the "chosen_shipping_methods" with the following code (Ajax).
Get the Chosen Shipping method:
Set/Update the Chosen Shipping method (through Javascript/Ajax and
admin-ajax.php
):