Hello Support Team,
I’m reporting an issue with an older piece of code that needs HPOS (High-Performance Order Storage) compatibility and proper shipping address handling.
Current Code Problem:
– Does not support HPOS – Manually updates shipping meta without using WooCommerce’s recommended methods
Problematic Code Snippet:
add_action('woocommerce_checkout_update_order_meta', function ($order_id) {
$order = new WC_Order($order_id);
$orderData = $order->get_data();
// Multiple update_post_meta() calls
update_post_meta($order_id, '_shipping_first_name', ...);
update_post_meta($order_id, '_shipping_last_name', ...);
// ... multiple similar calls
Recommended Approach:
add_action('woocommerce_checkout_update_order_meta', function ($order_id) {
$order = wc_get_order($order_id);
if (!isset($_POST['ws_drop_point_blob'])) {
return;
}
$ws_drop_point_blob = json_decode(sanitize_text_field(urldecode(stripslashes($_POST['ws_drop_point_blob']))), true);
if (get_option('webshipper_save_droppoint_as_address', false) == 'yes') {
$zip = $ws_drop_point_blob['zip'];
if (isset($ws_drop_point_blob['routing_code'])) {
$zip = $zip . ':' . $ws_drop_point_blob['routing_code'];
}
$shipping_address = [
'first_name' => sanitize_text_field($order->get_billing_first_name()),
'last_name' => sanitize_text_field($order->get_billing_last_name()),
'company' => sanitize_text_field($ws_drop_point_blob['name']),
'address_1' => sanitize_text_field($ws_drop_point_blob['address_1']),
'address_2' => sanitize_text_field('Drop point:' . $ws_drop_point_blob['drop_point_id']),
'city' => sanitize_text_field($ws_drop_point_blob['city']),
'postcode' => sanitize_text_field($zip),
'country' => sanitize_text_field($ws_drop_point_blob['country_code'])
];
$order->set_address($shipping_address, 'shipping');
}
// Update drop point metadata using HPOS-compatible method
$order->update_meta_data('_drop_point_id', sanitize_text_field($ws_drop_point_blob['drop_point_id']));
$order->update_meta_data('_drop_point_company', sanitize_text_field($ws_drop_point_blob['name']));
// ... other metadata updates
$order->save();
});
Key Improvements:
wc_get_order()
instead of new WC_Order()
set_address()
to update shipping addresswc_order_addresses
table is updatedupdate_meta_data()
for custom metadataQuestions:
Environment:
I get the following warning, when activating “Discount Rules For Woocommerce” (Plugin):
“Warning: Invalid argument supplied for foreach() in /var/www/site.dk/public_html/wp-content/plugins/webshipper-automated-shipping/WebshipperShippingRates.php on line 157”
I’m a new wordpress user, and don’t know how to resolve this error.
]]>There’s a bug, where you under certain circumstances can finish checkout without selecting a drop point.
It seems to happen if there’s no value set for the “Drop point required” message option (webshipper_drop_point_required
), and it then tries to get the fallback using esc_html_e()
. However this method echoes the translated value instead of returning it, meaning the error notice is never actually set for the checkout validation process, resulting in the error being ignored. esc_html__
should be used instead (specifically on line 126 of webshipper-automated-shipping.php
), and seems to solve the problem.
I couldn’t find any place to contribute to the project myself, so I’m hoping you can have this fixed by the next version release
]]>I am using wpml to tranlate my site. Pluvins shows shipping on cart page for sweedish version of site, but on english version it does not show. Is this plugin works with wpml?
Please help
Hi,
I have setup Webshipper with Klarna. It’s fetching shipping options via the Shipping API but it’s not fetching delivery_time on Klarna checkout page with KLarna shipping assistant. Here is my test site link https://dev1.hoodielab.com/ . Please check
Hello,
Just want to know what has been changed since version 1.4.4.2 as i have done some changes to the plugin for specific shipping methods to import and better mapping of orders/shipping methods.
Webshipper imports all orders so i have added option to set that only orders with specific shipping methods (instance_id) is imported.
Also i have found that webshipper imports shipping methods based on method_id in which is very wrong because you can have a lot of shipping methods using the same method_id. Correct will be to use instance_id as this always is unique.
Brgds
Rune