Home Forums WoodMart support forum ascending price by default

ascending price by default

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #590842

    rusakovs2005
    Participant

    Currently, products in the catalog are sorted by ascending price by default, but as a result, products with missing or zero prices are displayed first. How can we make sure that such products are positioned at the end of the list without changing the sorting method?

    I add this code but, not work in woodmart theme

    add_filter(‘posts_clauses’, ‘custom_orderby_price_with_zero_last_woodmart’, 10, 2);
    function custom_orderby_price_with_zero_last_woodmart($clauses, $query) {
    global $wpdb;

    // Проверяем, что это основной запрос WooCommerce и страница магазина или категории
    if (!is_admin() && $query->is_main_query() && (is_shop() || is_product_category()) && isset($query->query_vars[‘orderby’]) && $query->query_vars[‘orderby’] === ‘price’) {
    // Обеспечиваем, что все условия сортировки будут корректно применены
    $clauses[‘join’] .= ” LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = ‘_price’)”;
    $clauses[‘orderby’] = “IF({$wpdb->postmeta}.meta_value IS NULL OR {$wpdb->postmeta}.meta_value = ”, 1, 0), {$wpdb->postmeta}.meta_value+0 ASC”;
    }

    return $clauses;
    }

    #591010

    Hung Pham
    Keymaster

    Hi rusakovs2005,

    Thanks for reaching to us.

    Unfortunately, it requires complicated customization to make it work, which is out of our basic support.

    Thanks for understanding our limitations. Let me know if you have any questions.

    Kind Regards

Viewing 2 posts - 1 through 2 (of 2 total)