Okay
  Public Ticket #3982389
Request to Add “In-Stock First” Sorting Feature to Product Listings
Closed

Comments

  •  3
    YUJI OKUBO started the conversation

    Dear MarketKing Support Team,

    I hope you’re doing well. I’m using the premium version of MarketKing and would appreciate your assistance with customizing the product listing sort order.

    What I want to achieve
    On both the main product listing (/product) and each store’s product page (/(shop name)), I need in-stock items to appear first, while still displaying out-of-stock items afterward. In SQL terms, I’d like to prepend an “in-stock” condition to the ORDER BY clause, then apply whatever sort order the user has selected. For example, if sorting by price descending, the list should read:

    1. In-stock products — Price: high → low

    2. Out-of-stock products — Price: high → low

    Please note that out-of-stock items must remain visible—they should simply appear after all in-stock items.

    Background
    In Japanese e-commerce, it’s standard practice to list purchasable, in-stock items first, since customers cannot buy items that are out of stock. Prioritizing available stock in the sort order is therefore essential.

    Additional Context
    Japanese consumers are often described as the world’s most discerning, and I believe other markets can learn from our practices. Adding an “In Stock First” option would be a valuable enhancement, and as a Japanese user I would be delighted to see it included.

    My Request
    I already have the Code Snippets plugin installed. Could you please advise which MarketKing (or WooCommerce) hook(s) I should use and provide a code snippet example? A ready-to-use snippet would be extremely helpful.

    Thank you very much for your support. I look forward to your guidance.

    Best regards,
    大久保祐司

  •  2,435
    WebWizards replied

    Hi Yuji,

    Thanks for getting in touch and for providing such a detailed explanation,

    This is actually controlled by WooCommerce rather than MarketKing, since the frontend product display uses WooCommerce's core functionality. The good news is that I believe this can be achieved with a code snippet.

    I've prepared a code snippet that should help you implement this functionality. You can add this to your theme's functions.php file or using the Code Snippets plugin you already have installed:

    https://pastecode.io/s/2mpea68g

     

    Please try implementing this and let me know if that works for you,

    Kind regards,
    Stefan