• How to force a product bundle to change “stock status” when components run out of stock, when components arrive at the warehouse, return the bundle status?

Viewing 1 replies (of 1 total)
  • Thread Starter vguns

    (@vguns)

    I use the code to move products that are not available to the end of the list

    add_filter('posts_clauses', 'order_by_stock_status', 999);
    function order_by_stock_status($posts_clauses) {
        global $wpdb;
    	
        // only change query on WooCommerce loops
        if (is_product_category()||is_shop()||is_product_tag()) {
            $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
            $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
            $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
        }
        return $posts_clauses;

    maybe there is some working solution for products and bundles?

Viewing 1 replies (of 1 total)
  • The topic ‘Change stock status’ is closed to new replies.