diff --git a/includes/Commission/Settings/OrderItem.php b/includes/Commission/Settings/OrderItem.php index 78d8a8819c..0af06b0580 100644 --- a/includes/Commission/Settings/OrderItem.php +++ b/includes/Commission/Settings/OrderItem.php @@ -44,7 +44,7 @@ public function get(): Setting { $commission_type = $this->order_item->get_meta( '_dokan_commission_type', true ) ?? ''; $commission_source = $this->order_item->get_meta( '_dokan_commission_source', true ) ?? ''; $additional_flat = $this->order_item->get_meta( '_dokan_additional_fee', true ) ?? ''; - $commission_meta = $this->order_item->get_meta( 'dokan_commission_meta', true ); + $commission_meta = $this->order_item->get_meta( '_dokan_commission_meta', true ); // if dokan_commission_meta is exists the we don't need to map the flat amount because after 3.14.0 this maping is not needed. if ( $commission_type === Flat::SOURCE && ! is_array( $commission_meta ) ) { @@ -89,7 +89,7 @@ public function save( array $setting ): Setting { $this->order_item->update_meta_data( '_dokan_commission_rate', $settings->get_percentage() ); $this->order_item->update_meta_data( '_dokan_commission_type', $settings->get_type() ); $this->order_item->update_meta_data( '_dokan_additional_fee', $settings->get_flat() ); - $this->order_item->update_meta_data( 'dokan_commission_meta', $settings->get_meta_data() ); + $this->order_item->update_meta_data( '_dokan_commission_meta', $settings->get_meta_data() ); $this->order_item->save_meta_data(); $this->order_item->save(); diff --git a/includes/Order/Hooks.php b/includes/Order/Hooks.php index 1e01063b17..a3c23d3cf0 100644 --- a/includes/Order/Hooks.php +++ b/includes/Order/Hooks.php @@ -59,6 +59,21 @@ public function __construct() { add_filter( 'woocommerce_can_reduce_order_stock', [ $this, 'prevent_stock_reduction_for_parent_order' ], 10, 2 ); add_action( 'woocommerce_reduce_order_item_stock', [ $this, 'sync_parent_order_item_stock' ], 10, 3 ); + + // if _dokan_commission_meta does not exists, search for dokan_commission_meta + add_filter( 'woocommerce_order_item_get__dokan_commission_meta', [ $this, 'get_dokan_commission_meta' ], 10, 2 ); + } + + /** + * Retrieve commission meta using old dokan_commission_meta. + * + * @return mixed + */ + public function get_dokan_commission_meta( $value, $item ) { + if( empty( $value ) ) { + return $item->get_meta( 'dokan_commission_meta', true ); + } + return $value; } /** diff --git a/tests/pw/utils/helpers.ts b/tests/pw/utils/helpers.ts index 4a8c3702cb..da6608ac6c 100644 --- a/tests/pw/utils/helpers.ts +++ b/tests/pw/utils/helpers.ts @@ -247,7 +247,7 @@ export const helpers = { lineItems.forEach((item: any) => { item.meta_data.forEach((meta: any) => { - if (meta.key === 'dokan_commission_meta') { + if (meta.key === '_dokan_commission_meta') { totalAdminCommission += Number(meta.value.admin_commission); totalVendorEarning += Number(meta.value.vendor_earning); }