Skip to content

Commit f398615

Browse files
committed
feat: wooCommerce order status related triggers added
1 parent f2aa8f9 commit f398615

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

includes/Triggers/WC/Hooks.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
Hooks::add('woocommerce_add_to_cart', [WCController::class, 'handle_add_to_cart'], 10, 6);
2727
Hooks::add('woocommerce_cart_item_removed', [WCController::class, 'handle_removed_from_cart'], 10, 2);
2828

29+
Hooks::add('woocommerce_order_status_pending', [WCController::class, 'handle_order_status_pending'], 10, 1);
30+
Hooks::add('woocommerce_order_status_failed', [WCController::class, 'handle_order_status_failed'], 10, 1);
31+
Hooks::add('woocommerce_order_status_on-hold', [WCController::class, 'handle_order_status_on_hold'], 10, 1);
32+
Hooks::add('woocommerce_order_status_processing', [WCController::class, 'handle_order_status_processing'], 10, 1);
33+
Hooks::add('woocommerce_order_status_completed', [WCController::class, 'handle_order_status_completed'], 10, 1);
34+
Hooks::add('woocommerce_order_status_refunded', [WCController::class, 'handle_order_status_refunded'], 10, 1);
35+
Hooks::add('woocommerce_order_status_cancelled', [WCController::class, 'handle_order_status_cancelled'], 10, 1);
36+
2937
// Secondary hook form order create checkout
3038
Hooks::add('woocommerce_store_api_checkout_order_processed', [WCController::class, 'handle_order_checkout'], 10, 1);
3139

includes/Triggers/WC/WCController.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,41 @@ public static function handle_restore_order($order_id, $oldStatus, $newStatus, $
765765
Flow::execute('WC', static::RESTORE_ORDER, $orderData, $flows);
766766
}
767767

768+
public static function handle_order_status_pending($orderId)
769+
{
770+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_PENDING);
771+
}
772+
773+
public static function handle_order_status_failed($orderId)
774+
{
775+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_FAILED);
776+
}
777+
778+
public static function handle_order_status_on_hold($orderId)
779+
{
780+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_ON_HOLD);
781+
}
782+
783+
public static function handle_order_status_processing($orderId)
784+
{
785+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_PROCESSING);
786+
}
787+
788+
public static function handle_order_status_completed($orderId)
789+
{
790+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_COMPLETED);
791+
}
792+
793+
public static function handle_order_status_refunded($orderId)
794+
{
795+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_REFUNDED);
796+
}
797+
798+
public static function handle_order_status_cancelled($orderId)
799+
{
800+
return self::executeOrderStatusTrigger($orderId, static::ORDER_STATUS_SET_TO_CANCELLED);
801+
}
802+
768803
public static function handle_order_status_change($order_id, $from_status, $to_status, $this_order)
769804
{
770805
if (!static::isActivate()) {
@@ -1335,6 +1370,21 @@ public static function getVariationOfProduct($requestPrarams)
13351370
wp_send_json_success($allVariation, 200);
13361371
}
13371372

1373+
private static function executeOrderStatusTrigger($orderId, $triggeredEntityId)
1374+
{
1375+
if (!static::isActivate() || empty($orderId)) {
1376+
return false;
1377+
}
1378+
1379+
$flows = Flow::exists('WC', $triggeredEntityId);
1380+
if (empty($flows)) {
1381+
return false;
1382+
}
1383+
1384+
$orderData = WCHelper::processOrderData($orderId);
1385+
Flow::execute('WC', $triggeredEntityId, $orderData, $flows);
1386+
}
1387+
13381388
private static function executeProductTriggers($postId, $triggeredEntityId, $extra = [])
13391389
{
13401390
if (empty($postId) || empty($triggeredEntityId)) {

0 commit comments

Comments
 (0)