Automattic\WooCommerce\Admin\API\Reports\Customers
DataStore::get_last_order()
Retrieve the last order made by a customer.
Метод класса: DataStore{}
Хуков нет.
Возвращает
Объект
. WC_Order|false.
Использование
$result = DataStore::get_last_order( $customer_id );
- $customer_id(int) (обязательный)
- Customer ID.
Код DataStore::get_last_order() DataStore::get last order WC 9.7.1
public static function get_last_order( $customer_id ) { global $wpdb; $orders_table = $wpdb->prefix . 'wc_order_stats'; $last_order = $wpdb->get_var( $wpdb->prepare( // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT order_id, date_created_gmt FROM {$orders_table} WHERE customer_id = %d ORDER BY date_created_gmt DESC, order_id DESC LIMIT 1", // phpcs:enable $customer_id ) ); if ( ! $last_order ) { return false; } return wc_get_order( absint( $last_order ) ); }