In WooCommerce, the product variants are children of the actual product. So perhaps just check if the $product_id you’re on is a child, and if so get the title of the parent.
Untested code:
// Check if product has parent
if($product->post_parent){
$parents = get_post_ancestors( $product->ID );
/* Get the top Level page->ID count base 1, array base 0 so -1 */
$parentId = ($parents) ? $parents[count($parents)-1]: $product->ID;
$product->name = get_the_title($parentId);
}else{
$product->name = get_the_title($product->ID);
}
Related Posts:
- How to Get Category Name When Export Products
- Hide prices and checkout functionality in woocommerce
- Woocommerce hook after creating order? [closed]
- Can’t set proper WooCommerce language translation [closed]
- How to authenticate custom API endpoint in WooCommerce [closed]
- Function to Set Product type in Woocommerce [closed]
- Updating WooCommerce variable product stock issue
- Add CSS class to add-to-cart button, Woocommerce [closed]
- Override core woocommerce class
- WooCommerce – Where is functions.php?
- Woocommerce Shipping module available only for type of products [closed]
- WooCommerce – Adding Custom Order Without No Product [closed]
- XML sitemap over product variations
- How to remove the woocommerce_checkout_process action hook in woocommerce if particular project in cart [closed]
- Manually add order item with fixed product_id in WooCommerce
- HTML in WooCommerce settings
- WooCommerce shop page orderby [closed]
- WooCommerce Custom Product to checkout
- Reduce Drop down Menu Width in WordPress
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- How to enable specific plugin only based around shop manager role?
- How to modify WCMP Rest API response?
- Woocommerce dependent plugin
- How to check current user before all actions and filters?
- I want to disable Cash on delivery based on product tag in woocommerce Checkout Page [closed]
- Is there a way to create custom product templates based on category on WooCommerce?
- CampaignMonitor for WooCommerce – Move subscribe button [closed]
- Pre booking doesn’t work with custom bootstrap modul in woocommerce [closed]
- WooCommerce specifc variations for specific user role [closed]
- Custom Pages for Woocommerce Product-Category Pages
- Woocommerce Minimum Price for a Composite Product to add in cart
- Redirect to another page using contact form 7? [closed]
- Is there a way to get plugins and themes not built for multisite to work on a network subsite?
- How to get a list of bundled products using wp_query in woocommerce
- Add item to the woocommerce dashboard menu from a plugin
- How to get the particular product quantity in orders in Woocommerce [closed]
- Get orders of a specific customer woocommerce
- wc_get_template new template does not showing up
- Woocommerce – WordPress Roles & Capabilities
- Custom template for all woo commerce categories
- Search users with custom meta data
- Is it possible to instantiate a new WC_Cart?
- How to change layout of shop page in wordpress? [closed]
- Automatic recurring payment using YITH subscription and Dokan Stripe
- apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart
- Change Dashboard URL from wp-admin to wp-admin/index.php
- How To Use do_shortcode with WooCommerce One Page Checkout
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- Hide fields in woocommerce settings
- Visual composer custom element error
- Bulk Edit Media Library alt, caption, image names
- woocommerce: Customize email with item total count
- Plugin which unlock free gift when you reach some amount in cart
- Save order without sending the invoice / order details woocommerce [closed]
- Optimise wordpress database using SQL after deleting registered images from Media Folder
- is there a way to display product gallery images via cdn
- show wc_add notices on particular page in woo commerce custom plugin development
- Woocommerce redirection if no previous orders
- How to assign a specific service to a specific provider based on location
- Make modification of add_to_cart button specific to single page
- How to get the checkout form data from checkout page when place-order button is clicked
- Product Page loads terribly slow when product gallery images are added
- How to make WooCommerce multiple filter with custom meta fields
- One WooCommerce Store to multi distributor sites
- Custom form data not displaying in cart page?
- best way to handle subscriptions with a licence?
- how can export data in excel file custom plugin
- Is there a request for products plugin for WooCommerce
- woocommerce with external ftp site
- Export to csv adding html to file
- Object of class WP_Error could not be converted to string in /formatting.php
- Only return taxonomies that are linked to a category & product
- WordPress eMails not working
- Add WooCommerce vendor slug to auto-generated SKU
- Custom plugin issue – Notice: Trying to get property of non-object in
- fetch price from different table woocommerce
- Cannot save a custom meta field in quick edit
- how to make settings page for woocommerce plugin?
- redirect to a custom page
- wordpress plugin translation not working
- Many to many relationship for variable products
- Change value of Points earned in product data
- Problem with conditional woocommerce custom checkout field
- change product image url in widgets & shop page
- How woo-commerce store Product Data value in DB?
- Not getting result using ajax on wordpress
- Which WordPress version to use for improved plugin compatibility? [closed]
- Move related products after product summary? [closed]
- Turning Existing Eccommerce Site into Multi-SIte
- Trying to disable all notifications except for one on woocommerce checkout page with css [closed]
- Woocommerce – Product Description heading [closed]
- Visual Composer Data Source?
- Woocommerce disable checkout on specific day
- Hook for single product thumbnail
- Translate text for empty product
- Create Custom Coupon Type
- Update acf field in woocommerce orders
- Add different sizes packaging boxes to orders plugin
- additional fields based on the quantity of products selected
- A multi-section WordPress store [closed]