'all_woo_products', // all_woo_products | specific_woo_products | all_woo_categories | specific_woo_categories | all_woo_tags | specific_woo_tags | all_woo_brands | specific_woo_brands 'exclude_products' => [], 'include_products' => [], 'exclude_categories' => [], 'include_categories' => [], 'exclude_tags' => [], 'include_tags' => [], 'exclude_brands' => [], 'include_brands' => [], 'author' => null, ] ); $product_ids = []; // 🔹 Case 1: All products if ( 'all_woo_products' === $args['type'] ) { $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'publish', ]; // Add author filter if provided (for vendor filtering) if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $query = new WP_Query( $query_args ); $product_ids = $query->posts; // Exclude specific products if ( ! empty( $args['exclude_products'] ) ) { $product_ids = array_diff($product_ids, $args['exclude_products']); } } // 🔹 Case 2: Specific products elseif ( 'specific_woo_products' === $args['type'] ) { $product_ids = $args['include_products']; if ( ! empty( $args['author'] ) && ! empty( $product_ids ) ) { $filtered_ids = get_posts( [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', 'post__in' => $product_ids, 'author' => $args['author'], ] ); $product_ids = $filtered_ids; } } // 🔹 Case 3: All categories elseif ( 'all_woo_categories' === $args['type'] ) { $categories = get_terms(['taxonomy' => 'product_cat', 'fields' => 'ids']); $excluded = $args['exclude_categories'] ?? []; if ( ! empty( $excluded ) ) { $categories = array_diff($categories, $excluded); } $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $categories, ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } // 🔹 Case 4: Specific categories elseif ( 'specific_woo_categories' === $args['type'] ) { $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $args['include_categories'], ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } // 🔹 Case 5: All tags elseif ( 'all_woo_tags' === $args['type'] ) { $tags = get_terms(['taxonomy' => 'product_tag', 'fields' => 'ids']); $excluded = $args['exclude_tags'] ?? []; if ( ! empty( $excluded ) ) { $tags = array_diff( $tags, $excluded ); } $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_tag', 'field' => 'term_id', 'terms' => $tags, ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } // 🔹 Case 6: Specific tags elseif ( 'specific_woo_tags' === $args['type'] ) { $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_tag', 'field' => 'term_id', 'terms' => $args['include_tags'], ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } // 🔹 Case 7: All brands elseif ( 'all_woo_brands' === $args['type'] ) { $brands = get_terms(['taxonomy' => 'product_brand', 'fields' => 'ids']); $excluded = $args['exclude_brands'] ?? []; if ( !empty($excluded) ) { $brands = array_diff($brands, $excluded); } $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_brand', 'field' => 'term_id', 'terms' => $brands, ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } // 🔹 Case 8: Specific brands elseif ( 'specific_woo_brands' === $args['type'] ) { $query_args = [ 'post_type' => 'product', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => [ [ 'taxonomy' => 'product_brand', 'field' => 'term_id', 'terms' => $args['include_brands'], ], ], ]; if ( ! empty( $args['author'] ) ) { $query_args['author'] = $args['author']; } $product_ids = get_posts( $query_args ); } return array_unique( $product_ids ); } /** * Check if the current user is a Dokan vendor * * @param int|null $user_id Optional. User ID to check. Defaults to current user. * @return bool True if user is a Dokan vendor, false otherwise. */ function optiontics_is_dokan_vendor( $user_id = null ) { if ( ! function_exists( 'dokan_is_user_seller' ) ) { return false; } if ( null === $user_id ) { $user_id = get_current_user_id(); } if ( ! dokan_is_user_seller( $user_id ) ) { return false; } // A seller whose selling is not enabled yet (pending approval) gets no // vendor access. return function_exists( 'dokan_is_seller_enabled' ) ? (bool) dokan_is_seller_enabled( $user_id ) : true; }