@@ -213,7 +213,7 @@ public static function fields($id)
213213 $ entity = null ;
214214 if ($ id <= static ::CUSTOMER_DELETED ) {
215215 $ entity = 'customer ' ;
216- } elseif ($ id <= static ::PRODUCT_DELETED || $ id == static ::RESTORE_PRODUCT ) {
216+ } elseif ($ id <= static ::PRODUCT_DELETED || $ id == static ::RESTORE_PRODUCT || $ id == static :: PRODUCT_STATUS_CHANGED ) {
217217 $ entity = 'product ' ;
218218 } elseif ($ id <= static ::ORDER_STATUS_CHANGED_TO_SPECIFIC_STATUS || $ id == static ::RESTORE_ORDER || $ id == static ::ORDER_SPECIFIC_CATEGORY || $ id == static ::USER_PURCHASES_A_VARIABLE_PRODUCT ) {
219219 $ entity = 'order ' ;
@@ -275,6 +275,19 @@ public static function fields($id)
275275 break ;
276276 }
277277
278+ if ($ id == static ::PRODUCT_STATUS_CHANGED ) {
279+ $ fields = array_merge ($ fields , [
280+ 'Old Status ' => (object ) [
281+ 'fieldKey ' => 'old_status ' ,
282+ 'fieldName ' => __ ('Old Status ' , 'bit-integrations ' )
283+ ],
284+ 'New Status ' => (object ) [
285+ 'fieldKey ' => 'new_status ' ,
286+ 'fieldName ' => __ ('New Status ' , 'bit-integrations ' )
287+ ],
288+ ]);
289+ }
290+
278291 uksort ($ fields , 'strnatcasecmp ' );
279292
280293 $ fieldsNew = [];
@@ -441,11 +454,18 @@ public static function handle_product_action($new_status, $old_status, $post)
441454
442455 $ post_id = $ post ->ID ;
443456 if ($ new_status === 'trash ' ) {
444- return self ::handle_deleted_product ($ post_id );
457+ self ::handle_deleted_product ($ post_id );
445458 }
446459 if ($ old_status === 'trash ' ) {
447- return self ::handle_restore_product ($ post_id );
460+ self ::handle_restore_product ($ post_id );
448461 }
462+
463+ self ::handle_product_status_changed ($ post_id , $ new_status , $ old_status );
464+ }
465+
466+ public static function handle_product_status_changed ($ postId , $ newStatus , $ oldStatus )
467+ {
468+ return self ::executeProductTriggers ($ postId , static ::PRODUCT_STATUS_CHANGED , ['old_status ' => $ oldStatus , 'new_status ' => $ newStatus ]);
449469 }
450470
451471 public static function handle_deleted_product ($ postId )
@@ -1299,7 +1319,7 @@ public static function getVariationOfProduct($requestPrarams)
12991319 wp_send_json_success ($ allVariation , 200 );
13001320 }
13011321
1302- private static function executeProductTriggers ($ postId , $ triggeredEntityId )
1322+ private static function executeProductTriggers ($ postId , $ triggeredEntityId, $ extra = [] )
13031323 {
13041324 if (empty ($ postId ) || empty ($ triggeredEntityId )) {
13051325 return ;
@@ -1310,7 +1330,7 @@ private static function executeProductTriggers($postId, $triggeredEntityId)
13101330 return ;
13111331 }
13121332
1313- $ productData = WCHelper::processProductData ($ postId );
1333+ $ productData = WCHelper::processProductData ($ postId, $ extra );
13141334 Flow::execute ('WC ' , $ triggeredEntityId , $ productData , $ flows );
13151335 }
13161336
0 commit comments