Пожалуйста, помогите мне в сортировке списка товаров на странице магазина. Я пытался использовать этот код, но он всегда возвращает «Продукт не найден в соответствии с вашим выбором».
add_filter('woocommerce_get_catalog_ordering_args', 'wh_catalog_ordering_args');
function wh_catalog_ordering_args($args) {
global $wp_query;
if (isset($_GET['orderby'])) {
switch ($_GET['orderby']) {
//for attribute/taxonomy=pa_color
case 'pa_product-name' :
$args['order'] = 'ASC';
$args['meta_key'] = '_product_attributes';
$args['orderby'] = 'meta_value';
break;
}
}
return $args;
}
add_filter('woocommerce_catalog_orderby', 'wh_catalog_orderby');
function wh_catalog_orderby($sortby) {
$sortby['pa_product-name'] = 'Sort by Product Name: A - Z';
return $sortby;
}
add_action( 'save_post', 'save_woocommerce_attr_to_meta' );
function save_woocommerce_attr_to_meta( $post_id ) {
// 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] );
}
}
Пожалуйста, помогите мне