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.
- This topic has 8 replies, 3 voices, and was last updated 5 years, 8 months ago by Artem Temos.
-
AuthorPosts
-
April 10, 2019 at 2:40 pm #118072
abParticipantIs 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.April 10, 2019 at 6:19 pm #118098
Artem TemosKeymasterHello,
Unfortunately, it is not possible to sort products by that label on the shop page.
Kind Regards
April 10, 2019 at 6:39 pm #118107
Elise NoromitMemberHello,
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
April 11, 2019 at 2:58 am #118138
abParticipantHi 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;
}April 11, 2019 at 6:20 am #118148
Artem TemosKeymasterSorry, but we don’t have a working variant of such code for the new label products.
April 12, 2019 at 9:04 am #118380
abParticipantHI,
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.
April 12, 2019 at 9:23 am #118389
Artem TemosKeymasterHi,
Its key is
_woodmart_new_label
Regards
April 13, 2019 at 12:29 am #118553
abParticipantThank 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’ );April 13, 2019 at 7:17 am #118574
Artem TemosKeymasterGreat, thank you for posting your solution here!
-
AuthorPosts
The topic ‘Is it possible sort the products by "new" label on the product image.’ is closed to new replies.
- You must be logged in to create new topics. Login / Register