Ecommerce Shopify WordPress Discussion

Filter order view by products id in table order woocommerce

I am facing difficulties regarding filtering orders on the shop order page. Is there anyone who can help me with resolving this issue?, and I have created a new menu to display the 'Pending Concierge' order table, intending to show orders with a pending status. The issue I am currently facing is that when I add a new product ID for filtering and displaying in the order table. The code before if (current_user_can('dashboard_concierge')) { $product_ids = array(25491); and after I added the new product ID is as follows: if (current_user_can('dashboard_concierge')) { $product_ids = array(25491,1779,25485); it results in an error, and no results are displayed – the value becomes zero. and here the image result and this full code // Fungsi untuk memodifikasi tautan subsubsub function modify_subsubsub_actions($subsubsub) { global $wpdb; if (current_user_can('dashboard_concierge')) { $product_ids = array(25491,1779,25485); // // Generate placeholders for product IDs in the SQL query $placeholders = implode(', ', array_fill(0, count($product_ids), '%d')); $completed_menu_label = sprintf(__('Completed (%d Orders)', 'textdomain'), 0); $completed_menu_url = add_query_arg( array( 'post_status' => 'wc-completed', 'post_type' => 'shop_order', 'product_ids' => implode(',', $product_ids), 'concierge_menu' => 'completed', ), admin_url('edit.php') ); $pending_menu_label = sprintf(__('Pending Concierge (%d Orders)', 'textdomain'), 0); $pending_menu_url = add_query_arg( array( 'post_status' => 'wc-pending', 'post_type' => 'shop_order', 'product_ids' => implode(',', $product_ids), 'concierge_menu' => 'pending', ), admin_url('edit.php') ); $completed_orders_count = count(get_orders_ids_by_product_id_filter($product_ids, array('wc-completed'))); $completed_menu_label = sprintf(__('Completed (%d Orders)', 'textdomain'), $completed_orders_count); $subsubsub = array_slice($subsubsub, 0, 2, true) + array('completed' => '<a href="#" data-url="' . esc_url($completed_menu_url) . '" class="concierge-link">' . $completed_menu_label . '</a>') + array_slice($subsubsub, 2, null, true); $pending_orders_count = count(get_orders_ids_by_product_id_filter($product_ids, array('wc-pending'))); $pending_menu_label = sprintf(__('Pending Concierge (%d Orders)', 'textdomain'), $pending_orders_count); $subsubsub = array_slice($subsubsub, 0, 2, true) + array('pending_payment' => '<a href="#" data-url="' . esc_url($pending_menu_url) . '" class="concierge-link">' . $pending_menu_label . '</a>') + array_slice($subsubsub, 2, null, true); // skcript JavaScript for the link add_action('admin_footer', function () { ?> <script> jQuery(document).ready(function ($) { // Menangani klik pada tautan dengan class 'concierge-link' $('.concierge-link').on('click', function (e) { e.preventDefault(); // Mencegah navigasi default window.location.href = $(this).data('url'); // M }); }); </script> <?php }); // unset menu unset($subsubsub['all']); unset($subsubsub['wc-completed']); unset($subsubsub['wc-pending']); } return $subsubsub; } add_filter('views_edit-shop_order', 'modify_subsubsub_actions'); // Function to get product by id function get_orders_ids_by_product_id_filter($product_ids, $order_status = array('wc-completed','wc-pending')) { global $wpdb; // Generate placeholders for product IDs in the SQL query $placeholders = implode(', ', array_fill(0, count($product_ids), '%d')); // Query ID for order with another product id $results = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT order_items.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID WHERE posts.post_type = 'shop_order' AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' ) AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_product_id' AND CAST(order_item_meta.meta_value AS SIGNED) IN ($placeholders) GROUP BY order_items.order_id HAVING COUNT(DISTINCT order_item_meta.meta_value) = " . count($product_ids), ...$product_ids ) ); return $results; } // Filter for query function apply_product_filter_to_order_query($query) { global $pagenow, $post_type; if ($pagenow == 'edit.php' && $post_type == 'shop_order' && isset($_GET['product_ids'])) { $product_ids = array_map('intval', explode(',', $_GET['product_ids'])); $order_ids = get_orders_ids_by_product_id_filter($product_ids); if (!empty($order_ids)) { $query->query_vars['post__in'] = $order_ids; } } } add_action('pre_get_posts', 'apply_product_filter_to_order_query'); i try change the code but no luck
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.