plugin development - Can't get woocommerce_get_price_html to work

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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?

Share Improve this question edited Aug 8, 2019 at 15:58 edeb asked Aug 8, 2019 at 15:46 edebedeb 131 silver badge5 bronze badges 2
  • there is no actual question here – Jon Commented Aug 8, 2019 at 15:57
  • 1 sorry I forgot it :D but I placed it in the title – edeb Commented Aug 8, 2019 at 15:58
Add a comment  | 

1 Answer 1

Reset to default 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>';
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745257720a4619055.html

相关推荐

  • plugin development - Can&#39;t get woocommerce_get_price_html to work

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    4小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信