php - Display all products outside of filtered function

admin2025-01-07  6

I have a products page which displays products based on filters. I believe I have found the code in which all of the products are queried. Normally, if a customer selects an attribute such as 'Condition: Used', only products with that attribute will be shown. All of the non-attributed products in the filtered query are not shown.

I want to display all of the products not filtered to be shown below the filtered query. (ie: if someone clicks 'Condition: Used', all of the products that do not have the attribute of 'Used' are displayed below the original query.

I believe this is the code in which the filtered query is made:

    global $product;
    $product_id = $product->get_id(); // Get the ID of the current product

    // Check if the product is in the 'Base' category - filtered or not
    $is_base_category = has_term('base', 'product_cat', $product_id);

    
    // Helper function to get attribute value by attribute slug
    if (!function_exists('get_woocommerce_attribute_value')) {
        function get_woocommerce_attribute_value($product, $attribute_slug) {
            $taxonomy = 'pa_' . $attribute_slug;
            if ( taxonomy_exists( $taxonomy ) ) {
                // It's a global attribute
                $terms = wp_get_post_terms( $product->get_id(), $taxonomy );
                return !empty($terms) ? implode(', ', wp_list_pluck($terms, 'name')) : '';
            } else {
                // It's a custom product attribute
                $attributes = $product->get_attributes();
                if ( isset($attributes[$attribute_slug]) ) {
                    $attribute = $attributes[$attribute_slug];
                    if ( $attribute['is_taxonomy'] ) {
                        // It's a custom attribute saved as a taxonomy
                        $terms = wp_get_post_terms( $product->get_id(), $attribute['name'] );
                        return !empty($terms) ? implode(', ', wp_list_pluck($terms, 'name')) : '';
                    } else {
                        // It's a custom product attribute (not a taxonomy)

                        return $attribute['value'];
                    }
                }
            }
            return '';
        }
    }

EDIT: if not, are there any good plugins or ways to work with WooCommerce that would allow all of the products not selected to be shown below?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265087a1018.html

最新回复(0)