Поддержка WooCommerce Сортировка товаров по голосам пользователей

  • Добрый день!

    Мне необходимо добавить сортировку товаров по голосам пользователей из другого плагина.

    Нашел код, который добавляет произвольную сортировку в Woocommerce (код выполняется в function.php):

    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    function custom_woocommerce_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 ( 'random_list' == $orderby_value ) {
    $args['orderby'] = 'meta_value_datetime';//поле по которому сортируем
    $args['order'] = 'ASC';//по возрастанию (ASC) или убыванию (DESC)
    $args['meta_key'] = '';//по конкретному совпадению ключа
    }
    return $args;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortby['random_list'] = 'Сортировка по умолчанию';//название сортировки в админке и фронт энде
    return $sortby;
    }

    Есть api плагина:

    get_users_reviews()
    
    Description
    Get all user reviews of Reviewer plugin filtered by the defined templates ids. It return an array of
    users reviews. It works with Reviewer Box and Users Box and Auto Box types.
     
    Parameters
    The api requires the following parameters:
    - $templates (array) An array will the templates ids.
    - $sort (string) Define the sorting mode. Default: latest. Available: latest, top_score.
    - $limit (int) Define how many users reviews you want to return.
     
    Usage
    Call the api inside the source code of your theme or plugin.
    <?php $reviews = RWP_API::get_reviews_box_users_reviews( array( template_1,
    template_3 ), $sort, $limit ); ?>
    Reviewer Plugin v. 3.15.0 "29 di "31
     
    Output
    Array
    (
    [0] => Array
    (
    [rating_id] => rwp_rating_56b5c55ebe471
    [rating_post_id] => 33
    [rating_review_id] => 0
    [rating_score] => Array
    (
    [3] => 6.5
    [1] => 7.0
    )
    [rating_user_id] => 0
    [rating_user_name] => John
    [rating_user_email] => [email]dem@dkc.co[/email]
    [rating_title] => Lorem ipsum
    [rating_comment] => Ciao come va
    [rating_date] => 1454756718
    [rating_status] => published
    [rating_template] => rwp_template_56b31f19e53cf
    [rating_meta_id] => 66
    [rating_post_title] => Test Post
    [rating_user_avatar] => [url]http://.[/url] . .
    [rating_overall] => 6
    [rating_formatted_date] => 1 day ago
    [rating_url] => [url]http://domain.com/?rwpurid=rwp_rating_56b5c55ebe471[/url]
    [rating_template_maximum_score] => 10
    [rating_template_minimum_score] => 0
    [rating_template_low_pct] => 30
    [rating_template_high_pct] => 69
    [rating_template_low_score_color] => #56b258
    [rating_template_high_score_color] => #56b258
    [rating_template_medium_score_color] => #56b258
    [rating_template_rate_image] => http:// . . .
    )
    [1] => Array
    (
    [rating_id] => rwp_rating_56b5c55ebe471
    . . .
    )
    )

    Нужно вывести по «top_score» (8 сточка), подскажите пожалуйста как реализовать?
    Lanford на форуме Обратить внимание администрации на это сообщение 0

  • Тема «Сортировка товаров по голосам пользователей» закрыта для новых ответов.