I Have some minor question regarding visual settings

This topic has 4 replies, 3 voices, and was last updated 4 weeks ago ago by Tony Rodriguez

  • Avatar: Kulimary
    Kulimary
    Participant
    June 16, 2025 at 12:28

    Hello

    1. I wanted to setup my store so the out the stock products show last on my product list I used custom code which works but when i select sort by price or anything else the “out of stock” products are not affected , do you have any tips how can i improve my code?

    ‘// In-stock product show first on webshop
    add_filter(‘posts_clauses’, ‘custom_order_by_stock_status’, 2000);
    function custom_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} istock ON ({$wpdb->posts}.ID = istock.post_id)”;
    $posts_clauses[‘where’] .=
    ” AND istock.meta_key = ‘_stock_status’ AND istock.meta_value <> ””;
    // ‘instock’ sorts before ‘outofstock’ alphabetically
    $posts_clauses[‘orderby’] =
    ” istock.meta_value ASC, ” . $posts_clauses[‘orderby’];
    }
    return $posts_clauses;
    }’

    2. Question : Everytime i add product to cart a popup shows up with list what products i have, how can i disable it? and only show when I click on show cart icon? (attached img. add to cart popup)

    3. Question: On product catalog page the add to cart button is not alined with other products add to cart button due the different lenght of product name, how can I set it up so the grid is perfectly simetric? (attached image uneven product height)

    Files is visible for topic creator and
    support staff only.
    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    June 16, 2025 at 17:11

    Hi @Kulimary,

    1. You’re on the right track — your current code forces in-stock products to appear first in the default WooCommerce catalog view. However, the issue arises because WooCommerce’s sorting options like “Sort by price” or “Sort by popularity” override the posts_clauses you modified. That’s why your “in-stock first” logic is being ignored when users select another sort method.

    To fix this and preserve sorting by stock status across different sorting methods, you can take a slightly different approach that uses a custom orderby hook. Here’s a more flexible solution that applies the stock sorting only when it’s appropriate, and combines better with existing Woo sorting options.

    
    add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_ordering_args');
    function custom_woocommerce_catalog_ordering_args($args) {
        // Add meta_query to prioritize in-stock products
        $args['meta_query'][] = array(
            'key'     => '_stock_status',
            'value'   => 'outofstock',
            'compare' => '!=',
        );
    
        return $args;
    }
    
    add_filter('posts_clauses', 'custom_orderby_stock_status_clauses', 100, 2);
    function custom_orderby_stock_status_clauses($clauses, $query) {
        if (!is_admin() && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
            global $wpdb;
    
            // Only add the join if not already sorting by stock status
            if (strpos($clauses['join'], 'istock') === false) {
                $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS istock ON {$wpdb->posts}.ID = istock.post_id AND istock.meta_key = '_stock_status'";
            }
    
            // Append stock status sort to existing ORDER BY clause
            if (!empty($clauses['orderby'])) {
                $clauses['orderby'] = "istock.meta_value ASC, " . $clauses['orderby'];
            } else {
                $clauses['orderby'] = "istock.meta_value ASC";
            }
        }
    
        return $clauses;
    }
    

    2. Please navigate to Appearance > Theme Options > WooCommerce(shop) > Shop > Shop Page Layout > Product added notification > select None: https://prnt.sc/h1_jQMd3fcDp.

    3. Please add this custom CSS codes under XStore > Theme Options > Theme Custom CSS > Global CSS:

    
    body .content-product .product-title {
        min-height: 50px;
    }
    

    Hope it helps!

    Best Regards,
    8Theme’s Team

    Avatar: Kulimary
    Kulimary
    Participant
    November 7, 2025 at 12:12

    Thanks for the support! My topic “I Have some minor question regarding visual settings” has been successfully resolved.

    Avatar: Tony Rodriguez
    Tony Rodriguez
    Support staff
    November 7, 2025 at 12:12

    Dear Kulimary,

    It’s great having you in our WordPress & WooCommerce community!

    Every insight you share helps us refine XStore and build tools that empower thousands of online store owners worldwide.

    Together, we grow stronger with every release.

    Topic closed.
    The 8Theme Team

  • Viewing 4 results - 1 through 4 (of 4 total)

The issue related to '‘I Have some minor question regarding visual settings’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.