Created
September 19, 2018 13:41
-
-
Save varun-pluginhive/134e7cf7743da10b7fd3fe51121275eb to your computer and use it in GitHub Desktop.
Snippet to start label generation if status changed to processing from Admin. WOOCOMMERCE UPS SHIPPING PLUGIN WITH PRINT LABEL - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
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
/** | |
* Snippet to start label generation if status changed to processing from Admin. | |
* Created at : 19 Sep 2018 | |
* Updated at : 19 Sep 2018 | |
* PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
* Gist Link : https://gist.github.com/varun-pluginhive/134e7cf7743da10b7fd3fe51121275eb | |
*/ | |
if( ! function_exists('trigger_ups_label_generation') ) { | |
function trigger_label_generation_externally( $order_id ) { | |
$order = new WC_Order($order_id); | |
$order_items = $order->get_items(); | |
if( empty($order_items) && class_exists('WC_Admin_Meta_Boxes') ) { | |
WC_Admin_Meta_Boxes::add_error( __( 'UPS - No product Found. Please check the products in order.', 'ups-woocommerce-shipping' ) ); | |
return; | |
} | |
// Automatically Generate Packages | |
$current_minute=(integer)date('i'); | |
$package_url=admin_url( '/post.php?wf_ups_generate_packages='.base64_encode('|'.$order_id).'&auto_generate='.md5($current_minute) ); | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_URL,$package_url); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | |
$output=curl_exec($ch); | |
if( ! $output && curl_errno($ch) ) { | |
WC_Admin_Meta_Boxes::add_error( __( 'UPS - Curl error while automatic package generation. Error number - ', 'ups-woocommerce-shipping' ). curl_errno($ch) ); | |
} | |
curl_close($ch); | |
} | |
function trigger_ups_label_generation( $order_id, $old_status, $new_status ) { | |
if( is_admin() ) { | |
if( $new_status == 'processing' ) { | |
trigger_label_generation_externally($order_id); | |
} | |
} | |
} | |
add_action('woocommerce_order_status_changed', 'trigger_ups_label_generation', 10, 3 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment