Help with implementing PHP code
-
Hey WooCommerce team,
I am trying to implement the solution suggested by this user:
https://stackoverflow.com/questions/46688978/how-can-i-get-the-latest-order-id-in-woocommerceIt clearly indicates that the first portion of the code should be in the functions.php
function get_last_order_id(){ global $wpdb; $statuses = array_keys(wc_get_order_statuses()); $statuses = implode( "','", $statuses ); // Getting last Order ID (max value) $results = $wpdb->get_col( " SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type LIKE 'shop_order' AND post_status IN ('$statuses') " ); return reset($results); }
However, where should I be replacing the second half of the code?
$latest_order_id = get_last_order_id(); // Last order ID $order = wc_get_order( $latest_order_id ); // Get an instance of the WC_Order oject $order_details = $order->get_data(); // Get the order data in an array // Raw output test echo '<pre>'; print_r( $order_details ); echo '</pre>';
I tried placing it in functions.php but it throws up an error message.
Thanks.
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Help with implementing PHP code’ is closed to new replies.