PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 All 35 releases
automatorwp / integrations / woocommerce-shipstation / includes / triggers / order-shipped.php

order-shipped.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/woocommerce-shipstation/includes/triggers/order-shipped.php

134 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order Shipped
4 *
5 * @package AutomatorWP\Integrations\WooCommerce_ShipStation\Triggers\Order_Shipped
6 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 class AutomatorWP_WooCommerce_ShipStation_Order_Shipped extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'woocommerce_shipstation';
15 public $trigger = 'woocommerce_order_shipped';
16
17 /**
18 * Register the trigger
19 *
20 * @since 1.0.0
21 */
22 public function register() {
23
24 automatorwp_register_trigger( $this->trigger, array(
25 'integration' => $this->integration,
26 'label' => __( 'User\'s order gets shipped', 'automatorwp' ),
27 'select_option' => __( 'User\'s <strong>order</strong> gets shipped', 'automatorwp' ),
28 /* translators: %1$s: Number of times. */
29 'edit_label' => sprintf( __( 'User\'s order gets shipped %1$s time(s)', 'automatorwp' ), '{times}' ),
30 /* translators: %1$s: Order status. */
31 'log_label' => __( 'User\'s order gets shipped', 'automatorwp' ),
32 'action' => 'woocommerce_shipstation_shipnotify',
33 'function' => array( $this, 'listener' ),
34 'priority' => 10,
35 'accepted_args' => 2,
36 'options' => array(
37 'times' => automatorwp_utilities_times_option(),
38 ),
39 'tags' => array_merge(
40 automatorwp_woocommerce_shipstation_order_tags(),
41 automatorwp_woocommerce_shipstation_get_shipping_tags(),
42 automatorwp_utilities_times_tag()
43 )
44 ) );
45
46 }
47
48 /**
49 * Trigger listener
50 *
51 * @since 1.0.0
52 *
53 * @param WC_Order $order Order object
54 * @param array $args Additional data
55 */
56 public function listener( $order, $args ) {
57
58 // Bail if not order
59 if ( ! $order ) {
60 return;
61 }
62
63 $user_id = $order->get_user_id();
64
65 // Bail if not user
66 if ( $user_id === 0 ) {
67 return;
68 }
69
70 $order_id = $order->get_id();
71
72 // Shipping tags
73 $tracking_number = $args['tracking_number'];
74 $carrier = $args['carrier'];
75 $ship_date = date( 'Y-m-d', $args['ship_date'] );
76
77 // Trigger the order status change
78 automatorwp_trigger_event( array(
79 'trigger' => $this->trigger,
80 'user_id' => $user_id,
81 'order_id' => $order_id,
82 'tracking_number' => $tracking_number,
83 'carrier' => $carrier,
84 'ship_date' => $ship_date
85 ) );
86
87 }
88
89 /**
90 * Register the required hooks
91 *
92 * @since 1.0.0
93 */
94 public function hooks() {
95
96 // Log meta data
97 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
98
99 parent::hooks();
100 }
101
102 /**
103 * Trigger custom log meta
104 *
105 * @since 1.0.0
106 *
107 * @param array $log_meta Log meta data
108 * @param stdClass $trigger The trigger object
109 * @param int $user_id The user ID
110 * @param array $event Event information
111 * @param array $trigger_options The trigger's stored options
112 * @param stdClass $automation The trigger's automation object
113 *
114 * @return array
115 */
116 function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
117
118 // Bail if action type don't match this action
119 if( $trigger->type !== $this->trigger ) {
120 return $log_meta;
121 }
122
123 $log_meta['order_id'] = ( isset( $event['order_id'] ) ? $event['order_id'] : 0 );
124 $log_meta['tracking_number'] = ( isset( $event['tracking_number'] ) ? $event['tracking_number'] : '' );
125 $log_meta['carrier'] = ( isset( $event['carrier'] ) ? $event['carrier'] : '' );
126 $log_meta['ship_date'] = ( isset( $event['ship_date'] ) ? $event['ship_date'] : '' );
127
128 return $log_meta;
129
130 }
131
132 }
133
134 new AutomatorWP_WooCommerce_ShipStation_Order_Shipped();