[英]Wordpress get post field
I am overriding the admin email notification template in WooCommerce and when the order transaction is successful I want to add the transaction id in the email. 我在WooCommerce中覆盖了管理电子邮件通知模板,当订单交易成功时,我想在电子邮件中添加交易ID。
I tried $order->get_transaction_id()
as explained here in the admin email template, but it returns an empty result. 我按照管理员电子邮件模板中的说明尝试了$order->get_transaction_id()
,但返回的结果为空。
I then tried this in the admin email template: 然后,我在管理员电子邮件模板中尝试了此操作:
do_action('getOrderTransactionID', $order->id);
And in my theme's functions.php I added this but this function doesn't return anything either. 并且在主题的functions.php中添加了此功能,但此功能也不返回任何内容。
add_action('getOrderTransactionID', 'getOrderTransactionIDForEmail');
function getOrderTransactionIDForEmail($orderId){
echo get_metadata('post', $orderId, '_transaction_id', true);
//get_post_data doesn't return anything either
//get_post_meta( $orderId, '_transaction_id', true);
}
In the wp_postmeta
table, the _transaction_id
meta key is saved after each successful transaction. 在wp_postmeta
表中, _transaction_id
元密钥在每次成功交易后被保存。 Why then am I unable to retrieve the _transaction_id
which is already in the database? 为什么然后我无法检索数据库中已经存在的_transaction_id
?
What gateway are you using? 您正在使用哪个网关? If you don't see _transaction_id
then you need to save the returned transaction_id manually in your gateway plugin. 如果看不到_transaction_id
则需要在网关插件中手动保存返回的transaction_id。 Check out this page 查看此页面
Try saving transaction id in your payment gateway file, then try to see if it displays when you do var_dump(get_post_custom($order->id));
尝试将交易ID保存在您的付款网关文件中,然后尝试查看它是否在执行var_dump(get_post_custom($order->id));
add_post_meta( $order->id, '_transaction_id', YOUR_TRANSACTION_ID, true );
The following is an example of how to add data to email templates using existing hooks. 以下是如何使用现有挂钩将数据添加到电子邮件模板的示例。
function kia_display_email_order_meta( $order, $sent_to_admin, $plain_text ) {
$some_field = get_post_meta( $order->id, '_some_field', true ),
$another_field = get_post_meta( $order->id, '_another_field', true ),
if( $plain_text ){
echo 'The value for some field is ' . $some_field . ' while the value of another field is ' . $another_field;
} else {
echo '<p>The value for <strong>some field</strong> is ' . $some_field. ' while the value of <strong>another field</strong> is ' . $another_field;</p>;
}
}
add_action( 'woocommerce_email_order_meta', 'kia_display_email_order_meta', 30, 3 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.