Created
May 31, 2023 09:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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