WordPress 获取 post 字段
Wordpress get post field
我正在覆盖 WooCommerce 中的管理员电子邮件通知模板,当订单交易成功时,我想在电子邮件中添加交易 ID。
我在管理员电子邮件模板中尝试了 $order->get_transaction_id()
as explained here,但是 return 结果是空的。
然后我在管理员电子邮件模板中尝试了这个:
do_action('getOrderTransactionID', $order->id);
在我的主题 functions.php 中,我添加了这个,但是这个函数也没有 return 任何东西。
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);
}
在wp_postmeta
table中,_transaction_id
元键在每次成功交易后保存。为什么我无法检索数据库中已有的 _transaction_id
?
以下是如何使用现有挂钩将数据添加到电子邮件模板的示例。
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 );
您使用的是什么网关?如果您没有看到 _transaction_id
,那么您需要在您的网关插件中手动保存返回的 transaction_id。 Check out this page
尝试将交易 ID 保存在您的支付网关文件中,然后尝试查看它是否在您这样做时显示 var_dump(get_post_custom($order->id));
add_post_meta( $order->id, '_transaction_id', YOUR_TRANSACTION_ID, true );
我正在覆盖 WooCommerce 中的管理员电子邮件通知模板,当订单交易成功时,我想在电子邮件中添加交易 ID。
我在管理员电子邮件模板中尝试了 $order->get_transaction_id()
as explained here,但是 return 结果是空的。
然后我在管理员电子邮件模板中尝试了这个:
do_action('getOrderTransactionID', $order->id);
在我的主题 functions.php 中,我添加了这个,但是这个函数也没有 return 任何东西。
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);
}
在wp_postmeta
table中,_transaction_id
元键在每次成功交易后保存。为什么我无法检索数据库中已有的 _transaction_id
?
以下是如何使用现有挂钩将数据添加到电子邮件模板的示例。
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 );
您使用的是什么网关?如果您没有看到 _transaction_id
,那么您需要在您的网关插件中手动保存返回的 transaction_id。 Check out this page
尝试将交易 ID 保存在您的支付网关文件中,然后尝试查看它是否在您这样做时显示 var_dump(get_post_custom($order->id));
add_post_meta( $order->id, '_transaction_id', YOUR_TRANSACTION_ID, true );