Skip to content

Instantly share code, notes, and snippets.

@webdados
Created May 31, 2023 09:22
Show Gist options
  • Save webdados/8c13975798179c299daa60475376dc6e to your computer and use it in GitHub Desktop.
Save webdados/8c13975798179c299daa60475376dc6e to your computer and use it in GitHub Desktop.
Create a new service on DPD Portugal for WooCommerce (specifically for Switzerland, on this example), and pre-select it on the label issuing if the destination is that country
<?php
// Add new service to DPD Portugal for WooCommerce - Specific for Switzerland
add_filter( 'woo_dpd_portugal_available_services', 'custom_add_services_ch' );
function custom_add_services_ch( $services ) {
$services['custom_ch'] = 'Suiça';
return $services;
}
// Each time an order is for Switzerland, choose this service by default
add_filter( 'woo_dpd_portugal_default_shipment_service_for_order', 'custom_set_default_service_ch', 10, 2 );
function custom_set_default_service_ch( $default_service, $order ) {
if ( $order->get_shipping_country() == 'CH' ) {
return 'custom_ch';
}
return $default_service;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment