;
foreach( $customer_orders as $customer_order ) {
$order = wc_get_order ($customer_order – > ID);
$items = $order->get_items();
Foreach (convert $items to $item){
$product_id = $item->get_product_id();
$product_ids[] = $product_id;
}
}
$product_id returns; You can now combine the code from steps 1, 2, and 3 to create the following complete code:
Male function njengah_get_customer_purchase_history (){
\/\/Import current user object
$current_user = wp_get_current_user();
\/\/Verify that the user is valid
Return if (0 = = $current_user – > ID);
\/\/$args array creation
$args = array(
\
\
“meta_value”=>$current_user->ID,
‘post_type’ => wc_get_order_types(),
‘post_status’ => array_keys( wc_get_is_paid_statuses() ),
);
\/\/$args passed to get_posts() function
$customer_orders = get_posts($args);
\/\/Repeat the order and return the ID.
Return if (! $customer_orders);
$product_ids = array ();
foreach( $customer_orders as $customer_order ) {
$order = wc_get_order ($customer_order – > ID);
$items = $order->get_items();
Foreach (convert $items to $item){
$product_id = $item->get_product_id();
$product_ids[] = $product_id;
}
}
$product_id returns;
}Step 4: test the function return. In this step, you can use the print_r() function to check whether the function in step 3 displays data:
print_r(njengah_get_customer_purchase_history()); If you follow all the steps correctly, you will see that the data added to wp_head action hook is shown below. The data can now be used in shortcut code, theme or plug-in development to display the purchase history anywhere. Conclusion this article introduces how to display the goods purchased by users in woocommerce in stages. The ideal use of this code may lie in all the logic of comparing the current order product with the previous order product. Most practical applications include discount allocation based on previous orders or cross sales and upsell.
Similar article how to redirect when a WordPress page is refreshed? Refresh the page PHP aware practical example how to get the post ID from WordPress through slug woodcommerce how to get the current product category name WordPress how to get the logged in user information woodcommerce how to hide the product or category or role How to hide products? If you don’t log in to WordPress, how to redirect users? How to programmatically delete WordPress management menu items without page redirection plug-in? Wordcommerce depends on customers or user roles
Do not use the method plug-in that hides the management bar. Create a numbered method in WordPress. Change the method of return link in woodcommerce. Woodcommerce confirms not to log out: \