Products Compare has no settings screen, so its compare page address, product limit, list lifetime and rows are changed with two templates and seven filters. Add filters in a code snippets plugin or your child theme’s functions.php. Customizations like these aren’t covered by support, so test them on a staging site first.
For what the plugin does without any code, see Get started with Products Compare.
When you’d use this
- Give the compare page a different address or title.
- Let shoppers compare more or fewer than five products.
- Keep the compare list for longer or shorter than 7 days.
- Hide rows, or reorder them, on the compare page.
- Change the compare page’s or widget’s markup beyond what CSS can do.
Template overrides
Two templates in the plugin’s templates folder control what shoppers see:
products-compare-page-html.php: the compare page.content-widget-products-compare.php: the Products Compare for WooCommerce widget.
Copy the file into your child theme, either into its woocommerce folder or its root folder, and edit the copy. WordPress loads your theme’s copy instead of the plugin’s, so plugin updates don’t overwrite it. After an update, compare your copy with the plugin’s template in case it changed.
WooCommerce » Status has a Products Compare section whose Template Overrides row lists a copy of the compare page template in your theme’s root folder.
Filters
woocommerce_products_compare_end_point
Filters the compare page’s address, products-compare by default. The page sits at the root of your site, so my-comparison gives https://example.com/my-comparison/. After changing it, go to Settings » Permalinks and click Save Changes so WordPress picks up the new address.
woocommerce_products_compare_page_title
Filters the compare page’s title, "Products Compare" by default. It’s used for the browser tab, WooCommerce’s breadcrumb and Yoast SEO’s title and breadcrumb.
woocommerce_products_compare_max_products
Filters how many products a shopper can compare at once. Default 5. The alert shoppers see when they reach it uses the new number.
add_filter( 'woocommerce_products_compare_max_products', function () {
return 4;
} );
woocommerce_products_compare_cookie_expiry
Filters how many days the compare list is kept in the shopper’s browser. Default 7.
woocommerce_products_compare_compare_button
Filters the HTML of the Compare checkbox and the icon link to the compare page. It receives the HTML, the product ID and the checkbox’s checked attribute (empty when the product isn’t in the list). Keep the woocommerce-products-compare-compare-button class on the wrapper and the data-product-id attribute on the checkbox, because the plugin’s script relies on them.
woocommerce_products_compare_selected_products
Filters the products in the shopper’s compare list. The compare page, the widget and the checkboxes’ ticked state all use it.
woocommerce_products_compare_meta_headers
Filters the rows below the price on the compare page. It receives an array of row keys in display order: stock, sku, description, then each attribute’s name (for example pa_color). The Ratings and Price rows aren’t part of it.
To hide the SKU row:
add_filter( 'woocommerce_products_compare_meta_headers', function ( $headers ) {
return array_values( array_diff( $headers, array( 'sku' ) ) );
} );
Keep learning
- Get started with Products Compare (where the checkbox appears, the compare page and common issues)
- How to add custom CSS to your site (styling without template changes)
- Changing text in a plugin (rewording labels without code)
