Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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_Orders_Email Notifications - Fatal编程技术网

Php 根据Woocommerce电子邮件通知中的配送方式显示自定义内容

Php 根据Woocommerce电子邮件通知中的配送方式显示自定义内容,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,Woocommerce更新到3.2后,下面的代码不再有效 add_action( 'woocommerce_email_order_details', 'my_completed_order_email_instructions', 10, 4 ); function my_completed_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) { // Only for "Customer C

Woocommerce更新到3.2后,下面的代码不再有效

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

    // Only for "Customer Completed Order" email notification
    if( 'customer_completed_order' != $email->id ) return;

    // Comptibility With WC 3.0+
    if ( method_exists( $order, 'get_id' ) ) {
        $order_id = $order->get_id();
    } else {
        $order_id = $order->id;
    }
    //$order->has_shipping_method('')
    $shipping_method_arr = get_post_meta($order_id, '_shipping_method', false); // an array
    $rate_id = $shipping_method_arr[0][0]; // the rate ID

    if ( 'flat_rate:10' == $rate_id ){
        echo pll__("Text 1");
    } else {
        echo pll__("Text 2");
    }
}
此代码中有什么错误或过时的地方?

需要做哪些更改才能使其再次工作?

以下是获得订单中使用的装运方法并使此功能按预期工作的正确方法:

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

    // Only for "Customer Completed Order" email notification
    if( 'customer_completed_order' != $email->id ) return;

    $found = false; // Initializing variable

    // Iterating through Order shipping methods
    foreach($order->get_shipping_methods() as $value){
        $rate_id = $value->get_method_id(); // Get the shipping rate ID
        if ( 'flat_rate:10' == $rate_id )
            $found = true;
    }

    if ($found)
        echo '<p>'.__("Text 1 (found)","woocommerce").'</p>';
    else
        echo '<p>'.__("Text 2 (else)","woocommerce").'</p>';
}
add_action('woocommerce_email_order_details'、'my_completed_order_email_instructions',10,4);
功能我的\已完成\订单\电子邮件\说明($order、$sent\发送给\管理员、$plain\文本、$email){
//仅适用于“客户已完成订单”电子邮件通知
如果('customer\u completed\u order'!=$email->id)返回;
$found=false;//初始化变量
//迭代订单发货方法
foreach($order->get\u shipping\u methods()作为$value){
$rate_id=$value->get_method_id();//获取运费id
如果('flat\u rate:10'=$rate\u id)
$found=true;
}
如有($已找到)
回显“”。(文本1(找到)”,“woocommerce”)。

; 其他的 回音“”。(文本2(其他)”,“woocommerce”)。

; }
代码位于活动子主题(或主题)的function.php文件或任何插件文件中


已测试并运行…

您好。woocommerce 3.4版之后,代码似乎停止工作。有没有关于如何修复代码的想法?@Ugenijus好的,我需要一些时间来检查错误并进行更新。我会很快通知您。@Ugenijus似乎在Woocommerce 3.4中有一个与
Woocommerce\u email\u order\u details
action hook相关的bug。如果您尝试显示任何类似字符串的内容(没有任何限制)…则不会显示任何内容。我尝试使用其他电子邮件挂钩,但没有一个有效。所以这是Woocommerce团队将在下一版本中解决的一个bug。你认为他们有关于这个bug的信息吗?@Ugenijus我不知道,你可以尝试在Woocommerce Github上报告它……但这是一些黄金规则:1。woocommerce 3.4版是一个新的主要版本,对于生产来说太年轻了,仍然有一些bug(这将在未来的小更新中解决)。2.所有的插件和主题还没有完全兼容。3.始终在后台网站上测试更新。4.在应用Woocommerce主要版本更新之前,请始终等待一到两个月。