Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据签出选项添加自定义注释?_Php_Wordpress_Woocommerce - Fatal编程技术网

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()