admin管理员组文章数量:1296880
I am very new to PHP and WordPress. I have learned only the basics of filter hooks but this one seems to be a bit complicated. I want to replace the text This action will let you pay a deposit of
and for this product
preserving the value that is passed to %s
. I am hoping that someone will be able to help me out. Thank you.
<?php
echo wp_kses_post( apply_filters( 'yith_wcdp_deposit_only_message', sprintf( __( 'This action will let you pay a deposit of <span class="deposit-price">%s</span> for this product', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $deposit_value ) ), $deposit_value ) );
?>
I am very new to PHP and WordPress. I have learned only the basics of filter hooks but this one seems to be a bit complicated. I want to replace the text This action will let you pay a deposit of
and for this product
preserving the value that is passed to %s
. I am hoping that someone will be able to help me out. Thank you.
<?php
echo wp_kses_post( apply_filters( 'yith_wcdp_deposit_only_message', sprintf( __( 'This action will let you pay a deposit of <span class="deposit-price">%s</span> for this product', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $deposit_value ) ), $deposit_value ) );
?>
Share
Improve this question
asked Mar 31, 2021 at 3:47
Swastika RSwastika R
31 bronze badge
1 Answer
Reset to default 1It's easier to understand if you break it down. The code in your question is exactly the the same as this:
$message = sprintf( __( 'This action will let you pay a deposit of <span class="deposit-price">%s</span> for this product', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $deposit_value ) );
$message = apply_filters( 'yith_wcdp_deposit_only_message', $message, $deposit_value );
echo wp_kses_post( $message );
If you look at it that way, you can see that the yith_wcdp_deposit_only_message
filter is applied after the %s
has been substituted with wc_price( $deposit_value )
.
However, you can also see that the filter receives the $deposit_value
variable as its second argument, meaning that you can use it in your filter:
<?php
add_filter(
'yith_wcdp_deposit_only_message',
function( $message, $deposit_value ) {
$message = 'This is my new message, and the deposit value is ' . wc_price( $deposit_value );
return $message;
},
10,
2 // MUST be 2 to be able to use $deposit_value.
);
本文标签: functionsOverwrite text in a complicated filter hook
版权声明:本文标题:functions - Overwrite text in a complicated filter hook 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645324a2390152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论