Woocommerce: sort on a property

I have a woocommerce store. I want to sort results on default by a attribute I made: Levertijd

I already added this to [login to view URL]:

/************* Add sorting by attributes **************/


* Defines the criteria for sorting with options defined in the method below


add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');

function custom_woocommerce_get_catalog_ordering_args($args)


global $wp_query;

// Changed the $_SESSION to $_GET

if (isset($_GET['orderby'])) {

switch ($_GET['orderby']):

case 'pa_levertijd-asc':

$args['order'] = 'ASC';

$args['meta_key'] = 'pa_levertijd';

$args['orderby'] = 'meta_value';




return $args;



* Adds the sorting options to dropdown list .. The logic/criteria is in the method above


add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby');

add_filter('woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby');

function custom_woocommerce_catalog_orderby($sortby)


$sortby['pa_levertijd-asc'] = 'Sorteer op levertijd';

return $sortby;



* Save custom attributes as post's meta data as well so that we can use in sorting and searching


// add_action( 'save_post', 'save_woocommerce_attr_to_meta', 10, 3 );

function save_woocommerce_attr_to_meta($post_id, $post, $update)


if ($post->post_type != 'product') {return;}

// Get the attribute_names .. For each element get the index and the name of the attribute

// Then use the index to get the corresponding submitted value from the attribute_values array.

foreach ($_REQUEST['attribute_names'] as $index => $value) {

update_post_meta($post_id, $value, $_REQUEST['attribute_values'][$index]);



/************ End of Sorting ***************************/

It sort of works: see image on right top (it says Levertijd). However, the results still arent filtered on levertijd. It should be filtered on attribute levertijd alphabetical. So Direct leverbaar first, Levertijd 1-5 werkdagen sevond, levertijd 2-3 weken third etc.

1} How soon can you do this?

2 } Can you do it within 5$?

Taidot: PHP, WordPress, WooCommerce, MySQL, Tietojärjestelmäarkkitehtuuri

Näytä lisää: can html template craigs list, can repost daily craigs list, can upload flyer cregs list, can find private socks5 list, can add email contact list website, can buy adult email list, can genuine email ids list, can stream url channel list enigma2, woocommerce sort custom field, can export fan page list, sort products woocommerce sort, woocommerce sort criteria, can duns number master list, woocommerce sort custom fields, can i hire the property brothers, how can you see the full list of attributes of ui elements?, woocommerce sort list, once you are logged in redcap, where can you find the list of 18 hipaa identifiers?, can we define the text direction via css property, the "-list" option can be used to find the names of the schemes in the workspace.

Tietoa työnantajasta:
( 15 arvostelua ) Dhaka, Bangladesh

Projektin tunnus: #29439614

1 freelanceri on tarjonnut keskimäärin 4 $ tähän työhön


Hi we can look to work for your project if you are intrested pls reply, we will connect and forward the query to our developers and they will provide the solution

$4 CAD / tunti
(0 arvostelua)