• Resolved wovenheritagegh

    (@wovenheritagegh)


    Hello,

    if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
        add_filter('posts_clauses', 'order_by_stock_status', 2000);
    }
    
    function order_by_stock_status($posts_clauses) {
        global $wpdb;
      
        if (is_woocommerce() && (is_shop() || is_product_category() || 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;
    }

    i am using the above code to display out of stock products at the bottom of the page on my website, this code works perfectly on my shop page however does not work on pages where i use this shortcode to display products: [products limit=”8″ columns=”4″ orderby=”date” category=”zara men perfumes” cat_operator=”IN”].

    I would like to modify this shortcode to also show instock products first, or only show instock products. Thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @wovenheritagegh

    Thanks for reaching out!

    I would like to modify this shortcode to also show instock products first, or only show instock products

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

    Thread Starter wovenheritagegh

    (@wovenheritagegh)

    i am abit suprised that there is no option for ‘instock’ in the woocommerce shortcode list. i have read through and i dont see any that displays according to stock status.

    Plugin Support Zubair Zahid (woo-hc)

    (@doublezed2)

    Hello wovenheritagegh

    Thank you for your reply

    At WooCommerce we always try to balance the features and performance.
    That is why the default features of the WooCommerce plugin include only necessary features while extra features can be achieved by using plugins or custom code.

    However, we do have a Feature Request portal.
    Here users can request a feature that they wish to have in WooCommerce by default.

    Please don’t hesitate to contact us again if you have more questions or concerns. We are here to help ??

    Best regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WooCommerce shortcode’ is closed to new replies.