Get ordered product details (ID, quantity) in functions.php file of theme - WooCommerce

Asked
Active3 hr before
Viewed126 times

4 Answers

productdetails
90%

Meta Stack Overflow , Stack Overflow Public questions & answers , Stack Overflow help chat ,Thanks for contributing an answer to Stack Overflow!

Try this code;

add_action('template_redirect', 'woo_custom_redirect_after_purchase');

function woo_custom_redirect_after_purchase() {
   global $wp;
   global $product;
   if (is_checkout() && !empty($wp - > query_vars['order-received'])) {
      $order_id = isset($wp - > query_vars['order-received']) ? intval($wp - > query_vars['order-received']) : 0;
      $order = new WC_Order($order_id);
      $items = $order - > get_items();
      foreach($items as $item) {
         $product_id = $item['product_id'];
      }

      wp_redirect('http://example.com/success.php?pid='.$product_id);
      exit;
   }
}
88%

load more v
72%

How can I ask for customer id number as part of payment information? I am looking/expection a short filter, snippet to add to my functions.php Not a whole plugin. Thanks, Mulli June 16, 2020 How can I ask for customer id number as part of payment information? I am looking/expection a short filter, snippet to add to my functions.php Not a whole plugin. Thanks Reply Rodolfo Melogli June 27, 2020 Hi Mulli, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! Reply ,Hooks (do_action and apply_filters) use additional arguments which are passed on to the function. If they allow you to use the “$order” object you’re in business. Here’s how to get all the order information:,It’s also possible to gain $order information if you are in an email template. This can be helpful to show additional $order information in your transactional communications or trigger custom functions. Either way, enjoy!

load more v
65%

In early 2008 when I started working in WordPress/WooCommerce I hardly know StackOverflow and WooCommerce API, so I had to write several API for some of our web service. Then I had written this function to get order details by order/post ID. Hope this function will be helpful for you as well., How to Get Order Details by Order ID ,WooCommerce Shipment Tracking is an awesome paid plugin that you must have! If you want to add this in your custom order detail function then just add below code in above mentions.,First add getOrderDetailById() to your active theme functions.php or to any active plugin PHP file. Then call getOrderDetailById() from anywhere in your app by passing the Order ID like below.

load more v

Other "product-details" queries related to "Get ordered product details (ID, quantity) in functions.php file of theme - WooCommerce"