PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 1.1
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v1.1
2.0.2 trunk 0.2 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 2.0.0 2.0.1
texty / includes / Integrations / WooCommerce.php

WooCommerce.php in Texty – SMS Notification for WordPress, WooCommerce, Dokan and more 1.1, at includes/Integrations/WooCommerce.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Texty\Integrations;
4
5 /**
6 * WooCommerce Integration Class
7 */
8 class WooCommerce {
9
10 /**
11 * Initialize
12 */
13 public function __construct() {
14 add_action( 'woocommerce_order_status_changed', [ $this, 'order_status_changed' ], 10, 4 );
15 }
16
17 /**
18 * Send a message when an order status changes
19 *
20 * @param int $order_id
21 * @param string $old_status
22 * @param string $order_status
23 * @param WC_Order $order
24 *
25 * @return void
26 */
27 public function order_status_changed( $order_id, $old_status, $order_status, $order ) {
28 // don't process sub-orders
29 if ( $order->get_parent_id() ) {
30 return;
31 }
32
33 switch ( $order_status ) {
34 case 'on-hold':
35 $this->send( 'order_customer_hold', $order );
36 break;
37
38 case 'processing':
39 $this->send( 'order_admin_processing', $order );
40 $this->send( 'order_customer_processing', $order );
41 break;
42
43 case 'completed':
44 $this->send( 'order_admin_complete', $order );
45 $this->send( 'order_customer_complete', $order );
46 break;
47
48 default:
49 // code...
50 break;
51 }
52 }
53
54 /**
55 * Send notification by event
56 *
57 * @param string $event
58 * @param WC_Order $order
59 *
60 * @return void
61 */
62 private function send( $event, $order ) {
63 $class = texty()->notifications()->get( $event );
64 $notification = new $class();
65
66 $notification->set_order( $order );
67 $notification->send();
68 }
69 }
70