如果你把它分解一下,就会更容易理解。您问题中的代码与此完全相同:
$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 );
如果你这样看,你会发现
yith_wcdp_deposit_only_message
在
%s
已替换为
wc_price( $deposit_value )
.
但是,您还可以看到过滤器接收$deposit_value
变量作为其第二个参数,这意味着您可以在过滤器中使用它:
<?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.
);