WooCommerce 3.0+
you can get the order items of an order by
$order = wc_get_order( $order_id );
$items = $order->get_items();
then if you loop through the items, you can get all the relevant data:
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
}
a good tip is to check how the admin order pages get the data, you’ll find many answers there!
Pre-WooCommerce 3.0
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
}
Related Posts:
- Stop a plugin in the activation process when a certain WP version is not met then show error message in admin_notices action hook
- How to Add a Third Level Sub Menu to the WordPress Admin Menu
- How to Add an Index to Plugin Database table
- Override WordPress user with Oauth2 account
- How to add “Stick this post to the front page” to front end?
- Creating two database tables via plugin
- Is it a good idea to edit an already existing plugin to add more functionality?
- How to make media upload private? [duplicate]
- How to trace the cause of these PHP notices and warnings for class-wp-query.php?
- Admin plugin, how can I output a different content-type?
- Modify featured image URL at runtime
- Some plugins adding full server path after url (with custom wp-content folder)
- Custom Widget outputs the input but doesn’t save anything inside the textarea
- Woocommerce: Changing the variations select default value? [closed]
- Why load_textdomain work but not load_plugin_textdomain?
- Get uploaded image url
- Akismet plugin is deleting spam despite preferences
- Star rating for custom post types [closed]
- How to add custom JS to tinymce in wordpress
- Collaborative post submission [closed]
- Reuse javascripts from plugins within the theme
- $wpdb working with ajax but showing ajax error instead of success
- plugins_url function mixes system path and URL
- Inserting large amounts of data into a custom table during plugin install
- Wondering what these multi-colored extra pages are?
- Facebook Like needs confirmation?
- How does automatic redirection for the redirection plugin work?
- Need help restoring my WordPress blog
- Loading child theme script after plugins scripts
- Remove ALL css for a specific plugin page
- Is WP feature image function cropping images? WP Content Slideshow
- “Request has expired” with “Make your site social” (Gigya) plugin
- WordPress display breadcrumbs using Yoast plugin [closed]
- Linux Permissions and Ownership for WordPress
- how to use in custom single.php template using php?
- Automatically Assign Author to Category [closed]
- Howto check version of another plugin and then add a submenu page to it
- allow photo/video in comments
- Excluding private/protected posts via IP
- Can’t get Gutenberg InspectorControls to work
- Some one is trying to hack my website, Need guidance [closed]
- WordPress premium theme development [duplicate]
- Mass SQL WordPress Meta Key deletion
- Gathering and logging data from a plugin: how to do it without race conditions?
- How to pass the API key to the client from the database? [closed]
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- How do I make a secure API call from a shortcode when a button is clicked?
- Modify page title and subtitle with a plugin
- How to change the wp_upload_dir() path in plugin
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- How to add options to the plugin page?
- Odd /wp-admin/admin-ajax.php entries showing in Wassup
- wp-mail attachment is not sent for no reason?
- Plugin has added weird data in wp_options, set to autoload
- Setting Email locale before retrieving gettext translations
- how to execute some code after a post is published in WordPress [duplicate]
- Plugin to reformat the post automatically after submitting
- I can’t change permalink in WordPress 4.5.3
- Designing a plugin that uses an iFrame to process data in admin
- Could not add ‘LoginLogout’ link using BAW login logout plugin
- How to automatically activate users after registration without activation email?
- Pass PHP variable to javascript
- I want to add member to account in ultimate membership pro
- Using Remove Action Hook in Plugin
- Make downloadable ebook read online without download option
- WordPress rewrite rule depend on meta values not ids
- JS working when used normally but not in wordpress
- Do i need to use a plugin for third party api integration?
- Problem with wordpress has_action() function
- WordPress – WPBakery – Near Footer jump issue
- Dequeue Table of Content font
- Offering a freemium plugin (a free version + paid version)
- Display Woocommerce attribute name above product title
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- Remove special characters from filenames
- My WordPress admin Lost All admin option, roles & privileges?
- Tracking sales/conversions in Woocommerce using Google Analytics
- How to make a website with two types of logins , Sellers and buyers?
- Rogue splash page keeps popping up
- Making a Custom Post Type Plugin – keep getting the white screen of death
- Hook into install email
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Linking Plugin Files to WP
- Is there a way to include some external script to some or all pages in a wordpress site?
- Plugin activated but plugin files nowhere to be found
- Any plugins that upload, resize, and display images? [closed]
- How to load css files in a specific order
- Wysija Newsletters: Redirect After Subcription
- Upload images on 3D shape by customers
- Where to find remaining Boldgrid code in WP database?
- Notifications on WordPress Website [closed]
- Creating a Freemium plugin in the WordPress Repository
- Change from blogger to wordpress
- Add_rewrite_rule in HivePress (WordPress plugin/theme)
- Accessible ‘List Carousel’ block/pattern?
- My site has only one page, and users access my uploaded mp3 files from there – can I analyze access by song title?
- How to append TinyMCE editor in TinyMCE editor’s popup
- What plugin presents these extra columns in wp-admin -> plugins
- How to filter posts with a wp query by a custom dropdown type field with the magic fields plugin
- “All plugins are updated” but they aren’t