Last active
March 11, 2025 13:33
-
-
Save webdados/654f8508549fb760b65bec63c2123ddc to your computer and use it in GitHub Desktop.
Create a DPD Portugal shipping label programmatically with the "DPD Portugal for WooCommerce" WordPress plugin
This file contains hidden or 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 | |
// You need this plugin: https://www.webdados.pt/wordpress/plugins/dpd-portugal-para-woocommerce-wordpress/ | |
// Step 2 (ok) - 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 ); | |
// Step 2 (error) - 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 ); | |
// Step 1.1 - 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 ); | |
// Step 1 - Do it - Replace 16276 with your order id | |
// This could be inside woocommerce_order_status_changed and set the status to create the label | |
// Will call Step 1.1 and 2 automatically | |
do_action( 'woo_dpd_portugal_issue_label', 16276 ); | |
// More information: https://ptwooplugins.com/product/dpd-portugal-for-woocommerce/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment