自定义表中的序列号未显示在woommerce_mail_before_order_table操作中



我在WordPress中有一个带有序列号的自定义表。在使用Stripe进行测试后,我已成功将序列号显示在两个订单接收页面上:https://prnt.sc/9tz8i3BW7lJR

它也出现在WooCommerce管理订单页面上:

https://prnt.sc/jLyb5CQqSAH5

我正在使用woococommerce_email_before_order_table操作。(在客户完成订单上(我有下面的代码,我已经回复了订单ID和自定义表名,它们都出现在感谢与我们一起购物的电子邮件中。$license查询似乎没有返回任何内容,我只是不明白为什么它不会出现。如果我用$woo_order_id交换上一个订单号,如EMS-0051,则会显示序列号。此查询是否太早,并且在运行查询之前尚未在自定义表中填充?我不能让它工作。。有人能看到我做错了什么吗?下面是感谢电子邮件和代码。https://prnt.sc/38wa50jTyr3U

<?php

add_action( 'woocommerce_email_before_order_table', 'add_serial_to_email', 25, 4 ); 

function add_serial_to_email( $order, $sent_to_admin, $plain_text, $email ) {
global $wpdb;
$ipn_tables = $wpdb->prefix ."ipn_data_tbl";

///////BELOW is using 'seq Order No' plugin..this checks if WOO O/N or plugins O/N.
if (empty($order->get_id))  {      
$woo_order_id = $order->get_order_number();
}             
elseif (empty($order->get_order_number))  {
$woo_order_id  = $order->get_id();
}

///check order ID and Table name are there:
if (!empty($woo_order_id && $ipn_tables )) {
echo '<b>ORDER ID:</b>  '.$woo_order_id.'<br>'; // echos the Order ID - appears on "Thanks for shopping with us" email
echo '<b>TABLE NAME:</b>  '.$ipn_tables.'<br>';   // echo my Custom table name - appears on "Thanks for shopping with us" email
////But the below $license variable doesn't. I think it's a timing thing. 
//$license = $wpdb->get_var(" SELECT serial_no FROM $ipn_tables WHERE woo_order_id = $woo_order_id " );
$license = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM {$ipn_tables} WHERE woo_order_id = %s", $woo_order_id ) );
}

if ( $email->id == 'customer_completed_order' ){

printf( '<p class="custom-text">' .__( 'Your Software Serial Number:  '.'<span style="color:red;font-weight:bold;font-size:15px">'.$license ));
} 
}//function-END
?>

忘记显示MyPHPAdmin表:

https://prnt.sc/A4DH1v2STWrL

编辑:我应该提到,我对orderID和表进行了许可证检查,只是想看看它是否被检查过。。我的get_var查询似乎不起作用(空?(,但在我编辑的其他PHP页面中也使用了相同的查询。

看起来我发现了问题。事实上,'wocommerce_payment_complet'挂钩太早了但是在付款后但在订单状态更改之前以及在发送电子邮件之前,钩子'woocomerce_pre_payment_complet'首先被调用。:(所以我在add_action中所做的改变就是:woomocommerce_payment_complete到woomocommence_pre_payment_complete就是这样。它奏效了。add_action更新代码的一部分

最新更新