Skip to content

Commit e2b75c1

Browse files
committed
feat: wooCommerce removed from cart trigger added
1 parent eca54e8 commit e2b75c1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

includes/Triggers/WC/Hooks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Hooks::add('woocommerce_checkout_order_processed', [WCController::class, 'handle_variable_product_order'], 10, 2);
2525
Hooks::add('woocommerce_update_coupon', [WCController::class, 'handle_coupon_created'], 10, 2);
2626
Hooks::add('woocommerce_add_to_cart', [WCController::class, 'handle_add_to_cart'], 10, 6);
27+
Hooks::add('woocommerce_cart_item_removed', [WCController::class, 'handle_removed_from_cart'], 10, 2);
2728

2829
// Secondary hook form order create checkout
2930
Hooks::add('woocommerce_store_api_checkout_order_processed', [WCController::class, 'handle_order_checkout'], 10, 1);

includes/Triggers/WC/WCController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,27 @@ public static function handle_add_to_cart($cartItemKey, $productId, $quantity, $
546546
Flow::execute('WC', static::PRODUCT_ADD_TO_CART, $cartData, $flows);
547547
}
548548

549+
public static function handle_removed_from_cart($cartItemKey, $cart)
550+
{
551+
if (empty($cartItemKey) || empty($cart)) {
552+
return;
553+
}
554+
555+
$flows = Flow::exists('WC', static::PRODUCT_REMOVE_FROM_CART);
556+
if (empty($flows)) {
557+
return;
558+
}
559+
560+
$cartData = [
561+
'cart_item_key' => $cartItemKey,
562+
'applied_coupons' => $cart->applied_coupons,
563+
'cart_session_data' => $cart->cart_session_data,
564+
'removed_cart_contents' => array_values($cart->removed_cart_contents)
565+
];
566+
567+
Flow::execute('WC', static::PRODUCT_REMOVE_FROM_CART, $cartData, $flows);
568+
}
569+
549570
public static function handle_order_create($order_id, $fields)
550571
{
551572
if (!static::isActivate()) {

0 commit comments

Comments
 (0)