WOOT - WooCommerce Active Products Tables

Allow customers a way to show a list of their ordered products

Concerns the question of how to display products with a custom selection.

WOOT is flexible plugin, and if something is not obvious it is possible to resolve using hook ‘woot_filter_provider_‘. In this current article is described: “allow customers a way to order by showing them a list of their ordered products, sorted by their popularity (number of times they were ordered by that customer)“.

  • open file functions.php of the current WordPress theme (better use child theme)
  • place there next code:
    add_filter('woot_filter_provider_ordered_by_customer', function($args, $filter_data, $shortcode_args_set) {
    
        if (is_user_logged_in()) {
            // GET CURRENT USER
            $current_user = wp_get_current_user();
            if (0 == $current_user->ID) {
                return $args;
            }
    
            // GET USER ORDERS (COMPLETED + PROCESSING)
            $customer_orders = get_posts(array(
                'numberposts' => -1,
                'meta_key' => '_customer_user',
                'meta_value' => $current_user->ID,
                'post_type' => wc_get_order_types(),
                'post_status' => array_keys(wc_get_is_paid_statuses()),
            ));
    
            // LOOP THROUGH ORDERS AND GET PRODUCT IDS
            if (!$customer_orders) {
                $args['post__in'] = [-1];
                return $args;
            }
    
            $product_ids = [];
    
            foreach ($customer_orders as $customer_order) {
                $order = wc_get_order($customer_order->ID);
                $items = $order->get_items();
                foreach ($items as $item) {
                    $product_ids[] = $item->get_product_id();
                }
            }
    
            $args['post__in'] = array_unique($product_ids);
        }
    
    
        return $args;
    }, 10, 3);
  • on the page or place where you want to display current user boughed products use next shortcode: [woot  filter_provider=”ordered_by_customer” order_by=’popularity’] – where filter provider is arbitrary string and it is part of the custom hook  ‘woot_filter_provider_ordered_by_customer

 

By such logic site admin can create special functionality for himself, for example special page where to see products of any user by its user ID.