This is How to Display Related Products Based on Custom Taxonomy in WooCommerce
As an ecommerce store owner, one of your top priorities is to provide a seamless and engaging shopping experience for your customers. A key part of this is ensuring that your customers can easily discover and navigate to the right products.
One powerful way to do this is through the use of related product displays. By showing customers products that are related to the one they're currently viewing, you can increase the chances of them finding something else they're interested in and boosting your average order value.
However, the default WooCommerce related products feature can often fall short, displaying products that aren't truly relevant to the customer's interests. This is where custom taxonomies come in – by creating your own custom product categories, you can ensure that the related products shown are a perfect match.
In this article, we'll walk you through the step-by-step process of setting up custom taxonomies in WooCommerce and then integrating them into your product displays. Get ready to provide a personalized, engaging shopping experience that drives more sales!
Why Custom Taxonomies Matter for Related Products
The default WooCommerce related products feature uses the product's assigned categories to determine which items to display. While this can work, it often leads to a less-than-ideal experience:
- Broad categories: Many stores have fairly broad product categories, like "Clothing" or "Electronics". This means the related products shown may not be very specific or relevant to the customer's interests.
- Inconsistent categorization: If your store has multiple people managing the product catalog, there may be inconsistencies in how products are categorized. This can lead to irrelevant related products being shown.
- Limited flexibility: The default WooCommerce related products feature doesn't give you much control over the logic used to determine related items. You're stuck with the built-in category-based approach.
By creating your own custom taxonomies, you can overcome these limitations and take full control over how related products are displayed. Some key benefits include:
- Highly relevant recommendations: Custom taxonomies allow you to define product relationships based on your unique business logic, ensuring the related items shown are a perfect match for the customer's interests.
- Improved engagement and sales: Relevant related product displays can increase the chances of customers discovering additional products they want to buy, boosting your average order value.
- Better user experience: Customers are more likely to find what they're looking for and stay engaged with your store when the product recommendations are spot-on.
Ready to get started? Let's dive into the technical details.
Step 1: Create Custom Taxonomies in WooCommerce
The first step is to set up your custom taxonomies in WooCommerce. This will give you the flexibility to categorize your products in a way that makes the most sense for your business.
There are a few different ways to create custom taxonomies in WooCommerce. One popular option is to use a plugin like Custom Product Tabs for WooCommerce, which allows you to easily add custom product attributes and taxonomies.
Alternatively, you can add the custom taxonomies directly to your theme's functions.php file. Here's an example of how to create a custom "Brand" taxonomy:
// Add custom "Brand" taxonomy for products
function my_custom_taxonomy() {
$labels = array(
'name' => _x( 'Brands', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Brand', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Brands', 'textdomain' ),
'all_items' => __( 'All Brands', 'textdomain' ),
'parent_item' => __( 'Parent Brand', 'textdomain' ),
'parent_item_colon' => __( 'Parent Brand:', 'textdomain' ),
'edit_item' => __( 'Edit Brand', 'textdomain' ),
'update_item' => __( 'Update Brand', 'textdomain' ),
'add_new_item' => __( 'Add New Brand', 'textdomain' ),
'new_item_name' => __( 'New Brand Name', 'textdomain' ),
'menu_name' => __( 'Brands', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'brand' ),
);
register_taxonomy( 'product_brand', array( 'product' ), $args );
}
add_action( 'init', 'my_custom_taxonomy' );
In this example, we're creating a "Brand" taxonomy that can be assigned to individual products. You can customize the label names, whether the taxonomy is hierarchical, and other settings to fit your needs.
Once you've created your custom taxonomy, you can start assigning it to your products. You can do this either manually through the WordPress admin, or programmatically by hooking into the save_post
action and updating the custom taxonomy terms.
Step 2: Display Related Products Based on Custom Taxonomy
Now that you have your custom taxonomy set up, it's time to integrate it into your product displays. We'll focus on the related products section, but the same principles can be applied to other areas of your store as well.
The default WooCommerce related products display is controlled by the woocommerce_output_related_products
function. To override this and use our custom taxonomy, we'll need to create a custom function.
Here's an example of how you can do this:
// Display related products based on custom taxonomy
function my_woocommerce_output_related_products() {
global $product;
$args = array(
'post_type' => 'product',
'posts_per_page' => 4, // Number of related products to display
'post__not_in' => array( $product->get_id() ),
'orderby' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'product_brand', // Replace with your custom taxonomy name
'field' => 'term_id',
'terms' => wp_get_post_terms( $product->get_id(), 'product_brand', array( 'fields' => 'ids' ) ),
),
),
);
$related_products = new WP_Query( $args );
if ( $related_products->have_posts() ) {
echo '<section class="related products">';
echo '<h2>' . esc_html__( 'Related Products', 'textdomain' ) . '</h2>';
echo '<ul class="products columns-4">';
while ( $related_products->have_posts() ) {
$related_products->the_post();
wc_get_template_part( 'content', 'product' );
}
echo '</ul>';
echo '</section>';
}
wp_reset_postdata();
}
add_action( 'woocommerce_after_single_product_summary', 'my_woocommerce_output_related_products', 10 );
In this example, we're overriding the default woocommerce_output_related_products
function with our own custom function my_woocommerce_output_related_products()
. This function queries for related products based on the current product's assigned "Brand" taxonomy terms.
The key parts of this code are:
'tax_query'
: This tells WooCommerce to filter the related products based on the custom taxonomy we've defined (in this case, "product_brand").
wp_get_post_terms()
: This retrieves the taxonomy terms associated with the current product, which we then use in the tax query.
wc_get_template_part()
: This is the standard WooCommerce function for rendering the individual product items in the related products section.
You can customize this code further by adjusting the number of related products to display, the order they're displayed in, or any other parameters that fit your needs.
Bonus Tip: Leverage Flowpoint.ai for Smarter Related Products
While the custom taxonomy approach we've outlined above is a great way to improve your related product displays, there's an even more powerful solution available: Flowpoint.ai.
Flowpoint is a web analytics platform that uses advanced AI and machine learning to analyze your customer behavior and generate personalized product recommendations. Unlike the static, category-based approach of custom taxonomies, Flowpoint's recommendations are dynamic and adapt to each individual user's interests and browsing patterns.
Here are a few key benefits of using Flowpoint for your related products:
- Hyper-personalized recommendations: Flowpoint analyzes a wealth of user data, including browsing history, cart activity, and purchase behavior, to surface the most relevant products for each customer.
- Increased conversions and sales: Numerous studies have shown that personalized product recommendations can boost conversion rates by 10-30% or more.
- Effortless integration: Flowpoint integrates seamlessly with your WooCommerce store, allowing you to easily display the AI-generated related product recommendations on your product pages and throughout your store.
- Ongoing optimization: Flowpoint's algorithms continually learn and adapt, ensuring your related product displays are always optimized for maximum impact.
If you're serious about providing an engaging, personalized shopping experience for your customers, be sure to check out Flowpoint.ai. It could be the missing piece that takes your WooCommerce store to the next level.
Conclusion
Displaying relevant, engaging related products is a crucial element of any successful ecommerce store. By leveraging custom taxonomies in WooCommerce, you can take control of this process and ensure your customers are shown products that are truly tailored to their interests.
In this article, we've walked you through the step-by-step process of creating custom taxonomies and integrating them into your product displays. Remember, the key is to define your product relationships based on your unique business logic, not just the default category-based approach.
And if you really want to take your related products to the next level, be sure to check out Flowpoint.ai. Flowpoint's AI-powered recommendations can boost your conversion rates by providing hyper-personalized product suggestions that your customers will love.
Happy selling!
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.