1

I'm building a function to interact with the price html block in wordpress. This is my code

add_filter( 'woocommerce_get_price_html', array( $this, 'get_price_html' ));    
public function get_price_html( $product )
{
    echo '<a href="my-price">' . $product->get_price() . '</a>';
}

It's not working. What's wrong?

closed as off-topic by Nathan Johnson, Jacob Peattie, fuxia Aug 9 at 15:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • there is no actual question here – Jon Aug 8 at 15:57
  • 1
    sorry I forgot it :D but I placed it in the title – edeb Aug 8 at 15:58
0

I think your are missing parameters (even if you're not using those) as per its definition and always try to return into filters instead of echo the value. Try the following:

add_filter( 'woocommerce_get_price_html', array( $this, 'get_price_html' ), 10, 2);    
public function get_price_html( $price_html, $product )
{
    return '<a href="my-price">' . $product->get_price() . '</a>';
}

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