Home Forums WoodMart support forum Is it possible sort the products by "new" label on the product image.

Is it possible sort the products by "new" label on the product image.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #118072

    ab
    Participant

    Is it possible sort the products by “new” label on the product image. Plz refer to image for further clarification.

    Thanks in advance.

    Attachments:
    You must be logged in to view attached files.
    #118098

    Artem Temos
    Keymaster

    Hello,

    Unfortunately, it is not possible to sort products by that label on the shop page.

    Kind Regards

    #118107

    Hello,

    No, there is no option to do it on the shop page. New products are assigned by you. If they coincide with the most recent products, navigate to Appearance > Customize > Woocommerce > Product catalog and set the default sorting by most recent ones.

    Product grid element allows sorting by New. https://xtemos.com/docs/woodmart/faq-guides/product-grid-carousel-element/

    Best Regards

    #118138

    ab
    Participant

    Hi Elise,

    Thank u very much for the reply. What is the meta key of “new” label on the product listing. I found some sorting code on the internet and it might work;

    Can u please look at these codes; which I can add to the function. In this case now I can sort using “sale” – I felt that it might have same logic. I could be wrong, plz bear with me.

    // SORT BY SALE
    add_filter( ‘woocommerce_get_catalog_ordering_args’, ‘wcs_get_catalog_ordering_args’ );
    function wcs_get_catalog_ordering_args( $args ) {

    $orderby_value = isset( $_GET[‘orderby’] ) ? woocommerce_clean( $_GET[‘orderby’] ) : apply_filters( ‘woocommerce_default_catalog_orderby’, get_option( ‘woocommerce_default_catalog_orderby’ ) );
    if ( ‘on_sale’ == $orderby_value ) {

    $args[‘orderby’] = ‘meta_value_num’;
    $args[‘order’] = ‘DESC’;
    $args[‘meta_key’] = ‘_sale_price’;

    }
    return $args;
    }
    add_filter( ‘woocommerce_default_catalog_orderby_options’, ‘wcs_catalog_orderby’ );
    add_filter( ‘woocommerce_catalog_orderby’, ‘wcs_catalog_orderby’ );
    function wcs_catalog_orderby( $sortby ) {

    $sortby[‘on_sale’] = ‘On Sale’;
    return $sortby;
    }

    #118148

    Artem Temos
    Keymaster

    Sorry, but we don’t have a working variant of such code for the new label products.

    #118380

    ab
    Participant

    HI,

    Can u plz – just tell me the meta_key of “new” label on the product listings. I will figure out the rest. When I checked Add “New” label in the product page. It displays the “New” label on the product listing. So can u please give the meta_key of it.

    THanks in advance.

    #118389

    Artem Temos
    Keymaster

    Hi,

    Its key is _woodmart_new_label

    Regards

    #118553

    ab
    Participant

    Thank u very much for the meta key. I used following code and it works like a charm 🙂

    /**
    * Adds WooCommerce catalog sorting options using postmeta, such as custom
    **/
    function skyverge_add_postmeta_ordering_args( $sort_args ) {

    $orderby_value = isset( $_GET[‘orderby’] ) ? wc_clean( $_GET[‘orderby’] ) : apply_filters( ‘woocommerce_default_catalog_orderby’, get_option( ‘woocommerce_default_catalog_orderby’ ) );
    switch( $orderby_value ) {

    // Name your sortby key whatever you’d like; must correspond to the $sortby in the next function
    case ‘new_label’:
    $sort_args[‘orderby’] = ‘meta_value’;
    // Sort by meta_value because we’re using alphabetic sorting
    $sort_args[‘order’] = ‘asc’;
    $sort_args[‘meta_key’] = ‘_woodmart_new_label’;
    // use the meta key you’ve set for your custom field, i.e., something like “location” or “_wholesale_price”
    break;
    }

    return $sort_args;
    }
    add_filter( ‘woocommerce_get_catalog_ordering_args’, ‘skyverge_add_postmeta_ordering_args’ );
    // Add these new sorting arguments to the sortby options on the frontend
    function skyverge_add_new_postmeta_orderby( $sortby ) {

    // Adjust the text as desired
    $sortby[‘new_label’] = __( ‘Шинээр ирсэн’, ‘woocommerce’ );

    return $sortby;
    }
    add_filter( ‘woocommerce_default_catalog_orderby_options’, ‘skyverge_add_new_postmeta_orderby’ );
    add_filter( ‘woocommerce_catalog_orderby’, ‘skyverge_add_new_postmeta_orderby’ );

    #118574

    Artem Temos
    Keymaster

    Great, thank you for posting your solution here!

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

The topic ‘Is it possible sort the products by "new" label on the product image.’ is closed to new replies.