skip to Main Content

How to show woocommerce order in external php page not in the wordpress order page
i mean when a customer make an order through woocommerce I want to show the order in external php page like the order id and name and address and phone number in external php page but in the same path for wordpress.
thanks
Regards

2

Answers


  1. // 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();
    

    More information :

    IF you need data on rest of wordpress site use REST API :

    Login or Signup to reply.
  2. Copy the Woocommerce checkout template to your theme:
    wp-content/themes/my-theme/woocommerce/checkout/thankyou.php

    modify this page as you see fit to either redirect to a different page, add an include, etc. First, get your order number. Somewhere around like 40, (where the comments state "order successful"), get your order number:

    $myOrderNumber = $order->get_order_number();
    

    As long as you have the order id as a variable, getting order details is easy with a mysqli query:

    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
    

    This works completely outside of WordPress. You just need the database connection info from the wp-config.php file. You can find other attributes by searching the wp_postmeta table by order number in something like phpMyAdmin or SQL workbench if you want different info.

    Does this help?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search