0

I bought woocommerce compare plugin. Unfortunately I can't understand how to apply some filters.

For example I want to increase compare limit tom 10. How ı can use below filte?

apply_filters( ‘woocommerce_products_compare_max_products’, int ) – sets how many products can be compared at one time. Default is 5.

What I tried but not working;

   function comparelimit($location){
       $location = 10;
    }
    apply_filters( ‘woocommerce_products_compare_max_products’, 'comparelimit');

https://docs.woocommerce.com/document/woocommerce-products-compare/

3
2

You need to return the value in the function for it to be accessible outside that function

function comparelimit( $location ) {
    $location = 10;
    return $location;
}
add_filter( 'woocommerce_products_compare_max_products', 'comparelimit' );
1
  • Actually, I did try this too. But still see error message after 5 product. Tried again now. But still didn't work – roadlink Apr 23 at 22:09
0

Both are working now :) I don't know what changed.

Here is code for change product-compare page to what ever you want

function comparerename()
{
    return 'karsilastir';
}
add_filter('woocommerce_products_compare_end_point' ,'comparerename');

here is the code to change compare limit

function comparelimit( $location ) {
    $location = 8;
    return $location;
}
add_filter( 'woocommerce_products_compare_max_products', 'comparelimit' );

If anyone can teach me how to use below one, that would be great.

apply_filters( ‘woocommerce_products_compare_compare_button’, html ) – filters the display of the compare products button.

apply_filters( ‘woocommerce_products_compare_meta_headers’, array ) – filters the headers displayed on the compare products page.
-1

Weirdly this solved my problem.I am not sure if woocommerce's documentation is wrong.

    function comparelimit( $location ) {
    $location = 10;
    return $location;
}
add_action( 'woocommerce_products_compare_max_products', 'comparelimit' );
2
  • 'woocommerce_products_compare_max_products' is a filter not an action. There is no possible way this could work the way you say it worked. – Cornel Raiu Apr 24 at 8:10
  • Hi Cornel, I agree with you but working. Default it 5, as you see here it is 8 now for me. prnt.sc/121ecbs And this is the screenshot from code snippet plugin. prnt.sc/121eeio Do you have any suggestion? – roadlink Apr 25 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.