woocommerce offtopic - Accessing parameters when adding filter

admin2025-06-06  9

I am trying to change the out put of wc_get_rating_html using this filter

apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count);

So far this function works and of course doesn't make any changes.

add_filter('woocommerce_product_get_rating_html', 'change_rating_output');
function change_rating_output($html){
    return $html;
}

My question is that how I can access those $rating and $count parameters inside the function change_rating_output so that I can change the $html as I need.

I am trying to change the out put of wc_get_rating_html using this filter

apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count);

So far this function works and of course doesn't make any changes.

add_filter('woocommerce_product_get_rating_html', 'change_rating_output');
function change_rating_output($html){
    return $html;
}

My question is that how I can access those $rating and $count parameters inside the function change_rating_output so that I can change the $html as I need.

Share Improve this question asked Oct 30, 2018 at 10:37 agahiagahi 1013 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

When you call add_filter(), set the fourth parameter to 3 (which is the number of parameters accepted by the callback function which in your case is change_rating_output()), and then change your change_rating_output() function so that it accepts the $rating and $count parameters:

add_filter('woocommerce_product_get_rating_html', 'change_rating_output', 10, 3);
function change_rating_output($html, $rating, $count){
    // Now do what you want with $rating and $count
    return $html;
}

See http://developer.wordpress/reference/functions/add_filter/ for further details.

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

最新回复(0)