我在WordPress中有一个带有序列号的自定义表。在使用Stripe进行测试后,我成功地获得了出现在两个订单接收页面上的序列号:

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

我正在使用woocommerce_email_ am _order_table操作。(在customer_completed_ Order )下面有代码,我回显了订单ID和自定义TableName,它们都出现在感谢我们的电子邮件购物中。$license查询似乎什么也不返回,我只是不明白为什么它不会出现。如果我把$woo_order_id换成了以前的订单no,比如EMS-0051,序列号就会出现。这个查询是否太早,并且在运行查询之前还没有在自定义表中填充?我不能把它交给work..can,谁知道我做错了什么,好吗?感谢电子邮件和代码如下。

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 'ORDER ID: '.$woo_order_id.'
'; // echos the Order ID - appears on "Thanks for shopping with us" email
echo 'TABLE NAME: '.$ipn_tables.'
'; // echo my Custom table name - appears on "Thanks for shopping with us" email
////But the below $licence variable dosent. I think its 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( '' .__( 'Your Software Serial Number: '.''.$license ));
}
}//function-END
?>忘记显示MyPHPAdmin表:编辑:我应该提到我把orderID和表的许可检查放在这里,只是为了看看它是否是checked..it,我的get_var查询不工作(空的?)但是,在我编辑的其他PHP页面中也使用了相同的查询。发布于 2022-08-21 12:59:23
看来我发现了问题。事实上,'woocommerce_ payment _complete'钩子还太早,但是钩子'woocommerce_pre_payment_complete‘在付款后,在订单状态改变之前,在发送电子邮件之前,称为第一个。)所以我在add_action中所做的改变就是改变: woocommerce_payment_complete‘到woocommerce_pre_payment_complete --仅此而已。而且起作用了。添加的一部分_动作更新代码
https://wordpress.stackexchange.com/questions/408534
复制相似问题