Wie bekomme ich alle Bestelldetails in WordPress/Woocommerce? [duplicate]
Lesezeit: 5 Minuten
Suman Kalyan Mohanty
Ich verwende Woo-Commerce und versuche, alle Bestelldetails aus der Datenbank abzurufen. Ich bin neu darin und kann es nicht schaffen. Ich habe es bereits erstellt order_details.php Vorlage, wo ich alle Bestelldaten erhalten kann.
Danke für Ihren Schritt. Aber leider gibt es ein leeres Array zurück. Lassen Sie mich Ihnen erklären, dass ich woocommerce auf meinem lokalen Host installiert habe und es 2 Bestellungen darin gibt. Alles, was ich brauche, um diese Bestelldetails aus der Datenbank zu bekommen. Lassen Sie mich bitte wissen, wie um all diese Daten zu erhalten. @Dev Danidhariya
– Suman Kalyan Mohanty
28. Juli 2015 um 11:01 Uhr
‘globaler $woocommerce;’ Fügen Sie Top in meinem Code hinzu und überprüfen Sie.
– Dev Danidhariya
28. Juli 2015 um 13:08 Uhr
hallo lösen Sie Ihr Problem oder nicht.
– Dev Danidhariya
29. Juli 2015 um 13:47 Uhr
Noch nicht Bruder. 🙁 Versuch, ein Plugin zu ändern, um CSV-Bestelldetails zu exportieren.
– Suman Kalyan Mohanty
29. Juli 2015 um 14:42 Uhr
Fügen Sie einfach ‘post_status’ => ‘all’ hinzu und es werden alle Bestellungen zurückgegeben
– Mehbub Rashid
10. Juli 2021 um 6:10 Uhr
Rajilesh Panoli
$my_course_query = new WP_Query(array('post_type'=>'shop_order','post_status'=>'wc-completed'));
Ändern Sie den Status in den woococommerce-Status
Perfektionzzz! Vielen Dank
– Andy
26. September 2020 um 18:32 Uhr
Da ist zu viel oooo drin
– Akshay K. Nair
8. Juni um 6:19
Seit Woocommerce Mega Major Update 3.0+ hat sich einiges geändert:
Auf WC_Order-Eigenschaften kann wie zuvor nicht direkt zugegriffen werden, und es werden einige Fehler ausgegeben.
Neu WC_Order und WC_Abstract_Order Jetzt werden Getter- und Setter-Methoden benötigt.
Es gibt einige neue Klassen für Auftragsgegenstände:
WC_Order_Item-Klasse.
WC_Order_Item_Product-Klasse.
Daher sind auch die Eigenschaften der Bestellpositionen nicht wie zuvor in einer foreach-Schleife zugänglich und müssen verwendet werden diese spezifischen Getter- und Setter-Methoden stattdessen
// Get an instance of the WC_Order object (same as before)
$order = wc_get_order( $order_id );
// Get the order ID
$order_id = $order->get_id();
// Get the custumer ID
$order_id = $order->get_user_id();
Abrufen und Zugriff auf die Auftragsdateneigenschaften (in einem Array von Werten):
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
## Creation and modified WC_DateTime Object date string ##
// Using a formated date ( with php date() function as method)
$order_date_created = $order_data['date_created']->date('Y-m-d H:i:s');
$order_date_modified = $order_data['date_modified']->date('Y-m-d H:i:s');
// Using a timestamp ( with php getTimestamp() function as method)
$order_timestamp_created = $order_data['date_created']->getTimestamp();
$order_timestamp_modified = $order_data['date_modified']->getTimestamp();
$order_discount_total = $order_data['discount_total'];
$order_discount_tax = $order_data['discount_tax'];
$order_shipping_total = $order_data['shipping_total'];
$order_shipping_tax = $order_data['shipping_tax'];
$order_total = $order_data['cart_tax'];
$order_total_tax = $order_data['total_tax'];
$order_customer_id = $order_data['customer_id']; // ... and so on
## BILLING INFORMATION:
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_company = $order_data['billing']['company'];
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_postcode = $order_data['billing']['postcode'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_email = $order_data['billing']['email'];
$order_billing_phone = $order_data['billing']['phone'];
## SHIPPING INFORMATION:
$order_shipping_first_name = $order_data['shipping']['first_name'];
$order_shipping_last_name = $order_data['shipping']['last_name'];
$order_shipping_company = $order_data['shipping']['company'];
$order_shipping_address_1 = $order_data['shipping']['address_1'];
$order_shipping_address_2 = $order_data['shipping']['address_2'];
$order_shipping_city = $order_data['shipping']['city'];
$order_shipping_state = $order_data['shipping']['state'];
$order_shipping_postcode = $order_data['shipping']['postcode'];
$order_shipping_country = $order_data['shipping']['country'];
Holen Sie sich die Bestellartikel und greifen Sie mit den Methoden WC_Order_Item_Product und WC_Order_Item auf die Daten zu:
$order = wc_get_order($order_id);
// Iterating through each WC_Order_Item_Product objects
foreach ($order->get_items() as $item_key => $item_values):
## Using WC_Order_Item methods ##
// Item ID is directly accessible from the $item_key in the foreach loop or
$item_id = $item_values->get_id();
## Using WC_Order_Item_Product methods ##
$item_name = $item_values->get_name(); // Name of the product
$item_type = $item_values->get_type(); // Type of the order item ("line_item")
$product_id = $item_values->get_product_id(); // the Product id
$wc_product = $item_values->get_product(); // the WC_Product object
## Access Order Items data properties (in an array of values) ##
$item_data = $item_values->get_data();
$product_name = $item_data['name'];
$product_id = $item_data['product_id'];
$variation_id = $item_data['variation_id'];
$quantity = $item_data['quantity'];
$tax_class = $item_data['tax_class'];
$line_subtotal = $item_data['subtotal'];
$line_subtotal_tax = $item_data['subtotal_tax'];
$line_total = $item_data['total'];
$line_total_tax = $item_data['total_tax'];
endforeach;