如何在外部php页面而不是wordpress订单页面中显示wooccommerce订单我的意思是,当客户通过wooccommerce下单时,我想在外部php页面中显示订单,比如订单id、名称、地址和电话号码,但与wordpress的路径相同。谢谢问候
// Get 10 most recent order ids in date descending order.
$query = new WC_Order_Query( array(
'limit' => 10,
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
) );
$orders = $query->get_orders();
更多信息:
若您需要wordpress网站的其余部分的数据,请使用rest API:
将Wooccommerce结账模板复制到您的主题:wp-content/themes/my-themes/woocommerce/checkout/谢谢。php
根据需要修改此页面以重定向到其他页面、添加include等。首先,获取您的订单号。在大约40左右的地方(评论中写着"订单成功"(,获取您的订单号:
$myOrderNumber = $order->get_order_number();
只要您将订单id作为一个变量,使用mysqli查询就可以很容易地获取订单详细信息:
SELECT
wp_posts.ID as orderID,
wp_posts.post_date AS datePurchased,
v1.meta_value AS firstName,
v2.meta_value AS lastName,
v3.meta_value AS custEmail,
v4.meta_value AS custPhone,
v5.meta_value AS orderTotal
FROM wp_posts
INNER JOIN wp_postmeta v1 ON (wp_posts.ID = v1.post_id)
INNER JOIN wp_postmeta v2 ON (wp_posts.ID = v2.post_id)
INNER JOIN wp_postmeta v3 ON (wp_posts.ID = v3.post_id)
INNER JOIN wp_postmeta v4 ON (wp_posts.ID = v4.post_id)
INNER JOIN wp_postmeta v5 ON (wp_posts.ID = v5.post_id)
WHERE wp_posts.ID = '$myOrderNumber'
AND v1.meta_key = '_billing_first_name'
AND v2.meta_key = '_billing_last_name'
AND v3.meta_key = '_billing_email'
AND v4.meta_key = '_billing_phone'
AND v5.meta_key = '_order_total'
LIMIT 1
这完全在Wordpress之外工作。您只需要wp-config.php文件中的数据库连接信息。如果您想要不同的信息,可以通过在phpMyAdmin或SQL工作台中按订单号搜索wp_postmeta表来查找其他属性。
这有帮助吗?