Skip to content

Commit

Permalink
Merge branch 'develop' into feat/pro-2077-delivery-time-module-multip…
Browse files Browse the repository at this point in the history
…le-fix-and-enhancements
  • Loading branch information
aihimel committed Sep 4, 2023
2 parents 9eaf02e + 0e9a852 commit 26f0743
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 41 additions & 1 deletion includes/Order/Admin/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace WeDevs\Dokan\Order\Admin;

// don't call the file directly
use WeDevs\Dokan\Utilities\OrderUtil;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -21,8 +23,13 @@ class Permissions {
public function __construct() {
add_filter( 'map_meta_cap', [ $this, 'map_meta_caps' ], 12, 4 );

if ( OrderUtil::is_hpos_enabled() ) {
add_filter( 'woocommerce_order_list_table_prepare_items_query_args', [ $this, 'hpos_filter_orders_for_current_vendor' ] );
} else {
add_filter( 'posts_clauses', [ $this, 'filter_orders_for_current_vendor' ], 12, 2 );
}

// didn't added hpos support for below hooks, since tareq bhai asked to revoke admin access for vendors
add_filter( 'posts_clauses', [ $this, 'filter_orders_for_current_vendor' ], 12, 2 );
add_action( 'load-post.php', [ $this, 'revoke_change_order_status' ] );
add_filter( 'manage_edit-shop_order_columns', [ $this, 'remove_action_column' ], 15 );
add_filter( 'woocommerce_admin_order_preview_actions', [ $this, 'remove_action_button' ], 15 );
Expand Down Expand Up @@ -68,6 +75,39 @@ public function map_meta_caps( $caps, $cap, $user_id, $args ) {
return $caps;
}

/**
* Filter orders of current user
*
* @since DOKAN_SINCE
*
* @param array $args
*
* @return array
*/
public function hpos_filter_orders_for_current_vendor( $args ) {
// get the vendor id
$vendor_id = isset( $_GET['vendor_id'] ) ? absint( wp_unslash( $_GET['vendor_id'] ) ) : 0; // phpcs:ignore;
if ( ! current_user_can( 'manage_woocommerce' ) ) {
$vendor_id = dokan_get_current_user_id();
}

if ( ! $vendor_id ) {
return $args;
}

$meta_query = $args['meta_query'] ?? [];
$meta_query['meta_query'][] = [
[
'key' => '_dokan_vendor_id',
'value' => $vendor_id,
'compare' => '=',
'type' => 'NUMERIC',
],
];

return array_merge( $args, $meta_query );
}

/**
* Filter orders of current user
*
Expand Down
2 changes: 1 addition & 1 deletion includes/Order/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public function maybe_split_orders( $parent_order_id, $force_create = false ) {

//dokan_log( sprintf( 'New Order #%d created. Init sub order.', $parent_order_id ) );

if ( $force_create && wc_string_to_bool( $parent_order->get_meta( 'has_sub_order' ) ) === true ) {
if ( $force_create || wc_string_to_bool( $parent_order->get_meta( 'has_sub_order' ) ) === true ) {
$child_orders = $this->get_child_orders( $parent_order->get_id() );

foreach ( $child_orders as $child_order ) {
Expand Down

0 comments on commit 26f0743

Please sign in to comment.