• Resolved N.g

    (@loralora)


    Hello
    thanks for the support and great plugin!
    Please tell me – I have a code and it works fine for filtering in the Product by the pa_brand attribute. (code below)

    add_action( 'restrict_manage_posts', 'aws_brand_products_sorting' );
    function aws_brand_products_sorting() {
    global $typenow;
    $post_type = 'product'; // change to your post type
    $taxonomy = 'pa_brand'; // change to your taxonomy
    if ($typenow == $post_type) {
    $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
    $info_taxonomy = get_taxonomy($taxonomy);
    //$selected = isset($_GET[$info_taxonomy->name]) ? $_GET[$info_taxonomy->name] : '';
    wp_dropdown_categories(array(
    'show_option_all' => __("Brand {$info_taxonomy->label}", "aws-multi-functions"),
    'taxonomy' => $taxonomy,
    'name' => $taxonomy,
    'orderby' => 'name',
    'selected' => $selected,
    'show_count' => true,
    'hide_empty' => true,
    ));
    };
    }
    add_filter( 'parse_query', 'aws_brand_products_sorting_query' );
    function aws_brand_products_sorting_query( $query ) {
    global $pagenow;
    $post_type = 'product'; // change to your post type
    $taxonomy = 'pa_brand'; // change to your taxonomy
    $q_vars = &$query->query_vars;
    if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
    $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
    $q_vars[$taxonomy] = $term->slug;
    }
    }

    But I need to add more filtering on the pa_seller attribute.
    I am changing the name of the attribute – please see the code below. – but it doesn’t work.

    add_action( 'restrict_manage_posts', 'aws_seller_products_sorting' );
    function aws_seller_products_sorting() {
        global $typenow;
        $post_type = 'product'; // change to your post type
        $taxonomy  = 'pa_seller'; // change to your taxonomy
        if ($typenow == $post_type) {
            $selected      = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
            $info_taxonomy = get_taxonomy($taxonomy);
            //$selected      = isset($_GET[$info_taxonomy->name]) ? $_GET[$info_taxonomy->name] : '';
            wp_dropdown_categories(array(
                'show_option_all' => __("Seller {$info_taxonomy->label}", "aws-multi-functions"),
                'taxonomy'        => $taxonomy,
                'name'            => $taxonomy,
                'orderby'         => 'name',
                'selected'        => $selected,
                'show_count'      => true,
                'hide_empty'      => true,
            ));
        };
    }
    add_filter( 'parse_query', 'aws_seller_products_sorting_query' );
    function aws_seller_products_sorting_query( $query ) {
        global $pagenow;
        $post_type = 'product'; // change to your post type
        $taxonomy  = 'pa_seller'; // change to your taxonomy
        $q_vars    = &$query->query_vars;
        if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
            $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
            $q_vars[$taxonomy] = $term->slug;
        }
    }

    Please help, what am I doing wrong with the second code and pa_seller attributes?
    Why is the second code not filtering? (the filtering and selection box appears, but the filtering itself does not occur).

    Thanks a lot for your help

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @loralora

    Thanks for reaching out!

    I understand that you are using the first code snippet above for filtering the Product by the pa_brand attribute. Then, you altered it in order to use it for filtering the Product by the pa_seller attribute, however, it is not working as expected, correct?

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

    Thread Starter N.g

    (@loralora)

    thank you

    It turns out that the code works if I specify pa_brand in it, but it does not work if I change pa_brand to pa_seller.

    I do not understand why?

    Both attributes are created and assigned to products…

    Hi there!

    It looks like we didn’t have anyone in the thread who could identify the problem. As we are not developers, we can’t say for sure what exactly is missing in the second code.

    If you are unable to find help from the free resources shared above, you can hire a developer from freelance marketplaces or talk with an expert to help with the project.

    I’m going to mark this thread as resolved for now as it seems there won’t be any more new replies regarding the problem.

    Thanks for your understanding ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘adding filtering by attributes to products’ is closed to new replies.