Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a DPD Portugal shipping label programmatically with the "DPD Portugal for WooCommerce" WordPress plugin
<?php
//You need this plugin: https://www.webdados.pt/wordpress/plugins/dpd-portugal-para-woocommerce-wordpress/
//Monitor the result (success) and do whatver you want with it - Needs to be set before running it
add_action( 'woo_dpd_portugal_label_issued', function( $order_id ) {
$order = wc_get_order( $order_id );
echo 'Label issued for order '.$order_id.' on '.$order->get_meta( '_woo_dpd_portugal_label_issued' ).'<br/>';
echo 'Tracking number(s): '.implode( ' / ', $order->get_meta( '_woo_dpd_portugal_tracking_number' ) ).'<br/>';
echo 'Label PDF URL: '.$order->get_meta( '_woo_dpd_portugal_pdf_url' ).'<br/>';
}, 10, 1 );
//Monitor the result (error) and do whatver you want with it - Needs to be set before running it
add_action( 'woo_dpd_portugal_label_issued_error', function( $order_id, $error_message ) {
//echo 'Label NOT issued for order '.$order_id.' - Error: '.$error_message;
wp_mail( 'email@domain', 'Label NOT issued for order '.$order_id, 'Error: '.$error_message );
}, 10, 2 );
//Set the service you want to use - recommended if you're issuing the label programmatically - Needs to be set before running it
add_filter( 'woo_dpd_portugal_shipment_data', function( $shipment_data, $order_id ) {
$shipment_data['service'] = 'dpd18'; //Or whatever...
return $shipment_data;
}, 10, 2 );
//Do it - Replace 16276 with your order id
do_action( 'woo_dpd_portugal_issue_label', 16276 );
//More information: https://www.webdados.pt/wordpress/plugins/dpd-portugal-para-woocommerce-wordpress/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment