Php 如何根据签出选项添加自定义注释?
我想根据结帐时是否选择了某些付款选项,为每个订单自动添加自定义备注Php 如何根据签出选项添加自定义注释?,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想根据结帐时是否选择了某些付款选项,为每个订单自动添加自定义备注 这将是客户订单注释下方的新行。在活动主题的functions.php中添加以下代码片段,以实现上述功能- function modify_woocommerce_checkout_posted_data_comments( $posted_data ){ // Add extra custom notes for COD payment if( isset( $posted_data['order_comment
这将是客户订单注释下方的新行。在活动主题的functions.php中添加以下代码片段,以实现上述功能-
function modify_woocommerce_checkout_posted_data_comments( $posted_data ){
// Add extra custom notes for COD payment
if( isset( $posted_data['order_comments'] ) && isset( $posted_data['payment_method'] ) && $posted_data['payment_method'] == 'cod' ) {
$extra_note = __('Your custom notes goes here for COD payments.', 'textdomain' );
$posted_data['order_comments'] = nl2br( $posted_data['order_comments'] . "\n". $extra_note );
}
return $posted_data;
}
add_filter( 'woocommerce_checkout_posted_data', 'modify_woocommerce_checkout_posted_data_comments', 99 );
在这里,我添加了基于
货到付款方式的额外注释。根据您的要求更改此选项。太棒了,成功了!顺便问一下,新行显示为
,有没有办法更改它?为此,您可以删除上面的nl2br()