Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 根据发货和订单说明,向WooCommerce客户添加文本以完成订单电子邮件_Php_Wordpress_Woocommerce_Email Notifications_Shipping Method - Fatal编程技术网

Php 根据发货和订单说明,向WooCommerce客户添加文本以完成订单电子邮件

Php 根据发货和订单说明,向WooCommerce客户添加文本以完成订单电子邮件,php,wordpress,woocommerce,email-notifications,shipping-method,Php,Wordpress,Woocommerce,Email Notifications,Shipping Method,我正试图根据发货情况,如果/如果订单注释为空,将信息添加到客户完整的订单电子邮件中 根据订单注释字段是否填写,显示两条不同的消息。我已经下了测试订单,但什么也没出现 这是我正在尝试使用的代码: add_action( 'woocommerce_email_order_details', 'local_pickup_order_instructions', 10, 4 ); function local_pickup_order_instructions( $order, $sent_to_adm

我正试图根据发货情况,如果/如果订单注释为空,将信息添加到客户完整的订单电子邮件中

根据订单注释字段是否填写,显示两条不同的消息。我已经下了测试订单,但什么也没出现

这是我正在尝试使用的代码:

add_action( 'woocommerce_email_order_details', 'local_pickup_order_instructions', 10, 4 );
function local_pickup_order_instructions( $order, $sent_to_admin, $plain_text, $email ) {

    if ( 'customer_completed_order' != $email->id ) return;

    foreach( $order->get_items('shipping') as $shipping_item ) {

        $shipping_rate_id = $shipping_item->get_method_id();

        $method_array = explode(':', $shipping_rate_id );

        $shipping_method_id = reset($method_array);

    if ('local_pickup' == $shipping_method_id && empty($_POST['order_comments'])){ ?>

        <div style="">Your instructions text here</div>

    <?php

    break;
    }
        else {

    if ('local_pickup' == $shipping_method_id && !empty($_POST['order_comments'] ) ) { ?>

        <div style="">Your instructions text here</div>
    
        <?php

        }
    }
}
}
add_action('woocommerce_email_order_details','local_pick_order_instructions',10,4);
函数本地取货订单指令($order,$sent,$to,$admin,$plain,$email){
如果('customer\u completed\u order'!=$email->id)返回;
foreach($order->get_items('shipping')作为$shipping_item){
$shipping\u rate\u id=$shipping\u item->get\u method\u id();
$method\u array=explode(“:”,$shipping\u rate\u id);
$shipping\u method\u id=重置($method\u数组);
如果($本地收货==$发货方法\u id&&空($POST['order\u comments']){?>
您的说明文本在这里
您的说明文本在这里

您的代码中有一些错误…要在发货方式为“本地取货”时显示不同的自定义文本,如果有(或没有)客户通知,请使用以下简化和重新访问的代码:

add_action( 'woocommerce_email_order_details', 'local_pickup_order_instructions', 10, 4 );
function local_pickup_order_instructions( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id === 'customer_completed_order' ) {
        $shipping_items = $order->get_items('shipping');
        $shipping_item  = reset($shipping_items); // Get first shipping item
        $customer_note  = $order->get_customer_note(); // Get customer note

        // Targeting Local pickup shipping methods
        if ( strpos( $shipping_item->get_method_id(), 'local_pickup' ) !== false ) {
            if ( empty($customer_note) ) {
                echo '<div style="color:red;">'.__("Instructions text here… (NO costumer note)").'</div>'; // Empty order note
            } else {
                echo '<div style="color:green;">'.__("Instructions text here… (has a costumer note)").'</div>'; // Filled order note
            }
        }
    }
}
add_action('woocommerce_email_order_details','local_pick_order_instructions',10,4);
函数本地取货订单指令($order,$sent,$to,$admin,$plain,$email){
如果($email->id==='customer\u completed\u order'){
$shipping_items=$order->get_items('shipping');
$shipping\u item=reset($shipping\u items);//获取第一个装运项目
$customer_note=$order->get_customer_note();//get customer note
//以本地皮卡运输方式为目标
if(strpos($shipping\u item->get\u method\u id(),'local\u pickup')!==false){
if(空($customer_note)){
回显“”。_uu(“此处的说明文本…(无客户注释)”)。;//空订单注释
}否则{
回显“”。_uu(“此处的说明文本…(有客户注释)”)。;//已填写的订单注释
}
}
}
}
代码放在活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作