Best way to get shipping method being used? #44994
DavidAnderson684
started this conversation in
WooCommerce, Blocks, and Site Editing
Replies: 0 comments 2 replies
-
Yep, this is correct!
In the response to store API requests you can see which method is selected by the [
{
"package_id": 0,
"name": "Shipment 1",
"destination": {
"address_1": "123 Fake Street",
"address_2": "Testland",
"city": "Chicago",
"state": "IL",
"postcode": "60629",
"country": "US"
},
"items": [
{
"key": "758874998f5bd0c393da094e1967a72b",
"name": "XSS",
"quantity": 1
}
],
"shipping_rates": [
{
"rate_id": "free_shipping:1",
"name": "Free shipping",
"description": "",
"delivery_time": "",
"price": "0",
"taxes": "0",
"instance_id": 1,
"method_id": "free_shipping",
"meta_data": [
{
"key": "Items",
"value": "XSS × 1"
}
],
"selected": false,
"currency_code": "GBP",
"currency_symbol": "£",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "£",
"currency_suffix": ""
},
{
"rate_id": "flat_rate:2",
"name": "Flat rate",
"description": "",
"delivery_time": "",
"price": "700",
"taxes": "0",
"instance_id": 2,
"method_id": "flat_rate",
"meta_data": [
{
"key": "Items",
"value": "XSS × 1"
}
],
"selected": true,
"currency_code": "GBP",
"currency_symbol": "£",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "£",
"currency_suffix": ""
},
]
}
] Hope this helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When the
woocommerce_store_api_cart_errors
action is called (byCartController::validate_cart()
, in response to various cart-page actions), what is the best way to discover which is the current shipping method? (In PHP code that is run by that action, that is).Related to this, I note that the JSON response to actions that call this method (e.g.
/wc/store/v1/cart/remove-coupon
) includes a shipping calculation, but that response does not indicate which method was used to make the calculation.Having looked over the code, I think that the answer is likely that it's with
wc()->session->get( 'chosen_shipping_methods' );
? It'd be helpful to have that confirmed or a pointer to any relevant documentation, though (I searched but didn't find any).Thank you!
Beta Was this translation helpful? Give feedback.
All reactions