Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created May 20, 2025 05:36
Show Gist options
  • Save goranefbl/c84a5c2078ef9d770628d80db6c6ac6b to your computer and use it in GitHub Desktop.
Save goranefbl/c84a5c2078ef9d770628d80db6c6ac6b to your computer and use it in GitHub Desktop.
GLS Multiple Pickup locations
<?php
add_action('woocommerce_admin_order_data_after_order_details', 'gls_add_pickup_address_select');
function gls_add_pickup_address_select($order) {
$selected = $order->get_meta('_gls_pickup_location'); // HPOS-compatible
?>
<p class="form-field form-field-wide">
<label for="gls_pickup_location"><?php _e('Pickup Location', 'your-textdomain'); ?></label>
<select name="gls_pickup_location" id="gls_pickup_location">
<option value="">Default Store Address</option>
<option value="warehouse1" <?php selected($selected, 'warehouse1'); ?>>Warehouse 1 - Zagreb</option>
<option value="warehouse2" <?php selected($selected, 'warehouse2'); ?>>Warehouse 2 - Split</option>
</select>
</p>
<?php
}
add_action('woocommerce_process_shop_order_meta', 'gls_save_pickup_address_select');
function gls_save_pickup_address_select($order_id) {
if (isset($_POST['gls_pickup_location'])) {
$order = wc_get_order($order_id);
$order->update_meta_data('_gls_pickup_location', sanitize_text_field($_POST['gls_pickup_location']));
$order->save(); // Required for HPOS
}
}
add_filter('gls_shipping_for_woocommerce_api_get_pickup_address', function($pickup_address, $order) {
$pickup_location = $order->get_meta('_gls_pickup_location');
if ($pickup_location === 'warehouse1') {
return [
'Name' => 'Warehouse 1',
'Street' => 'Vukovarska 1',
'City' => 'Zagreb',
'ZipCode' => '10000',
'CountryIsoCode' => 'HR',
'ContactName' => 'Warehouse 1 Manager',
'ContactPhone' => '0123456789',
'ContactEmail' => '[email protected]'
];
}
if ($pickup_location === 'warehouse2') {
return [
'Name' => 'Warehouse 2',
'Street' => 'Obala kneza Branimira 3',
'City' => 'Split',
'ZipCode' => '21000',
'CountryIsoCode' => 'HR',
'ContactName' => 'Warehouse 2 Manager',
'ContactPhone' => '0987654321',
'ContactEmail' => '[email protected]'
];
}
// Otherwise, use default from the plugin
return $pickup_address;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment