Late to the party but here you go:
<?php
if( $product->is_type( 'simple' ) ){
// a simple product
} elseif( $product->is_type( 'variable' ) ){
// a variable product
}
// If you need a Product object for the above:
$product = new WC_Product( get_the_ID() );
Found it here: https://gist.github.com/patrickgilmour/9d4a28b4a2f0c1dcecbf and here https://wordpress.org/support/topic/condition-to-check-if-product-is-simple-or-variable.
I’m glad this question wasn’t closed 🙂
Related Posts:
- How to get variables from fucntion.php to my plugin files
- Getting RGBA colour from gutenberg colourpicker
- Global variables during plugin activation , deactivation and uninstall operarations
- Plugin. Html code in Template
- Set and access global variable
- Woocommerce Create custom product type with variations
- Add comments for template variables
- Passing stored variables to add_filter
- Add text to variable
- Passing PHP Variables to AJAX Loaded Pages
- Shortcode and variable
- What’s the best way to echo out a filter variable?
- Defining the value of a variable before a function?
- How to display emails as a post?
- Passing function into add_action always returns the first argument
- Defining constant in a plugin to use in another plugin
- How to display variables from plugin?
- fix undefined variable in native wp files
- Passing variable from template file to the plugin file
- Editing Global Variables from Inside Functions
- Global Handle to Class unavailable in Plugin?
- Translate a plugin using .po .mo files
- How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?
- Sending all emails using SMTP
- __(): What if I have to pass in a variable?
- How to make Pull Requests on a wordpress.org plugin?
- Custom Taxonomy in plugin and template
- Should we use plugins that aren’t available from the official WordPress site?
- Where can I propose a new plugin?
- Disallow a user to post in certain categories
- Why allow overriding crucial pluggable functions wp_verify_nonce and wp_create_nonce?
- is_post_type_archive not working in feed
- How to edit plugin’s html? [closed]
- Datepicker not supporting timepicker
- Add a Custom Permalink option in the Permalink Admin Screen?
- Escape special characters in image link
- Disable WordPress password reset via mails,instead notify admin about the reset request
- Can’t use the built-in wordpress install/upgrade plugin feature [closed]
- publish_post plugin hook doesn’t always pass $post->post_content
- Let user subscribe to specific categories
- WP Customer Reviews – shortcodes
- How to get a Jewish/English event calendar on a page in WordPress?
- Make menu page link inaccessible or disabled
- Advanced Custom Fields plugin – get text from editor field and save it in a variable
- How organize uploaded media in WP?
- Archive – same title for the first two posts
- Build a list of partners with Link, Logo and text
- How to hide some section in WordPress under Post
- is there a way to link one of the field in ACF field group, to a field in a media attachment page? [closed]
- Rewrite rule not matching
- Get errors from WP_Error to different variables
- Call specific plugin update
- How to get post ID with hooks publish_post, new_to_publish, etc
- How to enable customer login to customer specific admin page
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Is there a plugin for feedback like Kissmetrics available? [closed]
- Retrieve options set through a plugin
- How to Include Custom Post Content From Plugin
- How to redirect to a page after the form is submitted
- Exporting Custom Taxonomy in plugin
- Add background image/layout for single page?
- Separate jQuery for Individual Comments?
- Identify current wordpress theme
- How to write a new file when new post has been published in WordPress
- Using call_user_func() within add_settings_section() within a Class
- Paypal Framework
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- WordPress default post categories meta box widget
- Save order without sending the invoice / order details woocommerce [closed]
- Fatal error “Call to undefined function is_plugin_active” each time the plugin is activated
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- Product Page loads terribly slow when product gallery images are added
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Cannot display wordpress thumbnail
- How do I render content from a wp_editor in a plugin setting field?
- Only return taxonomies that are linked to a category & product
- Trying to remove a couple categories from shop page
- Enabling plugin on specific pages and subpages
- How can I disable Jetpack plugin on mobile?
- Not getting result using ajax on wordpress
- Error when renaming option
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- URL Rewriting from a Plugin based on custom values
- Plugin De/Activation Not Firing On MultiSite install
- Change All Login/Signup Links in Plugin
- Buddypress Plugin for register user from other site’s [closed]
- Need plugins and themes from clients site [closed]
- Permissions question [closed]
- Output dropdown results into Woocommerce Order details
- Need help with restricted page for users
- Display Video as Post Thumbnail
- Display products based on sub-categories
- how to embed a crop feature for cropping images uploaded by the user
- Fatal error: Uncaught Error: Call to a member function fetch_array() on bool
- Edit a page/post DB data?
- how to update WordPress plugins from external website with nodejs?
- this code is fiven by chat-gtp but nothing match even I key in the value of a cell. help!
- How do i fix this error?
- How do i display the number of images on the “post screen”