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
- How to export all content with feature images?
- Woocommerce Shop page variation product button replace with add to cart button
- How can I insert thousands of Woocommerce products by batch with PHP? [closed]
- WooCommerce search products between price range using WP_Query
- Redirect to another page using contact form 7? [closed]
- How to use add_submenu_page() for editors?
- PHP Error When a plugin is active
- woocommerce with custom post type
- Is there a way to get plugins and themes not built for multisite to work on a network subsite?
- Exact Hook to payment methods
- Restrict content based on buy woocommerce product
- How to get a list of bundled products using wp_query in woocommerce
- Adding Static Image to WooCommerce Content-Single-Product template
- Hide a Menu Item on Login
- Product count in archive page Title in WooCommerce [closed]
- Add item to the woocommerce dashboard menu from a plugin
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- How to get the particular product quantity in orders in Woocommerce [closed]
- Get Every Key & Value from Array then Display All in New Line
- Woocommerce Coupon Menu and Marketing Menu missing After “Coupons can now be managed from Marketing > Coupons.” [closed]
- Get orders of a specific customer woocommerce
- WooCommerce: Force coupon for existing/registered customers [closed]
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- wc_get_template new template does not showing up
- Show icons or badges under title on product archives/category pages
- Conditional Shipping Options if Certain Products are in Cart WooCommerce
- WordPress Stock Update Programatically
- Woocommerce Backend Search by Title and SKU
- Problem with add_action
- WooCommerce Shopping Cart Not Initially Showing Products [closed]
- How can I concatenate variables to search results title? [closed]
- WooCommerce: after install hook
- How to add a new column with text fields to WooCommerce Cart List?
- Add a “View all” button on WooCommerce product archives pages
- I am trying to make a field show and save from quickedit screen
- Woocommerce: limit user to see only the products he created
- Woocommerce singe product custom gallery output works just on the first slide
- How to include a custom field in the woocommerce email?
- woocommerce search by sku and title ajax
- Woocomerce add info after order email prouct item
- Remove Pagination for Product Category Pages WooCommerce
- add seperate suffix for low price and high price in woocommerce
- Get products list by url key in WordPress Woocommerce [closed]
- Cross Sells are not being shown in Cart Page. Please Help!
- How to display registered customer list as dropdown in WooCommerce checkout?
- How do I get the Payzone WooCommerce payment gateway plugin to show up in the settings? [closed]
- Error with get_price (and others) in self-written plugin to show price
- Export postmeta (custom fields)
- How to change WooCommece variation data programmtically [closed]
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- .php file for woocommerce edit category? [closed]
- Woocommerce – WordPress Roles & Capabilities
- Advanced Custom Fields (acf) – Filter Relationship by Taxonomies not Post Type
- Sending customer an email with link to stripe to make payment
- Override a Plugin Function
- Custom template for all woo commerce categories
- How to remove products-links after the product title using remove_action
- Search users with custom meta data
- WordPress Multi-Step Product Search
- Is it possible to instantiate a new WC_Cart?
- Woocommerce Free shipping method [closed]
- how get curent URL slug from archive page [closed]
- dynamically create callback functions inside a for loop
- Sell access to form [closed]
- get_term_meta returns false in widget
- Add key and value to an array in another file
- Custom search search does not work?
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- Disable variations on woo commerce if out of stock
- How to change layout of shop page in wordpress? [closed]
- I want to filter my products with attributes [closed]
- How to add category and subcategory in WordPress custom code?
- Woocommerce – Change Variable Product Add to Cart to behave like external product using Custom Field (link) [closed]
- Make 2 different WooCommerce checkout pages?
- How to return a specific attribute
- Automatic recurring payment using YITH subscription and Dokan Stripe
- Woocommerce checkout page broken when set as a checkout in woocommerce settings [closed]
- How to get custom minimum price in Woocommerce
- apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart
- Woocommerce Export and import Orders
- Edit all $wp_scripts at once to $in_footer = false
- Edit all $wp_scripts at once to $in_footer = false
- WordPress Phone Field Check (use numbers, spaces and pluses)
- Can export gallery but can’t import it Wp all import
- Restrict posts to customers with complete WooCommerce orders only
- WooCommerce – I want to add functionality of one plugin to another plugin — best approach?
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Get product categories and add them to a custom taxonomy
- How to make WooCommerce payment method field optional?
- How To Use do_shortcode with WooCommerce One Page Checkout
- Cannot read properties of undefined (reading ‘firstChild’) using photoswipe in product page
- woocommerce remove coupon link does not work
- WordPress – Ultimate Auction for WooCommerce
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- Plugins to generate reflinks in WordPress
- Working on a product group in wordpress, where user choose how many children, wife and husband
- product available stock day by day
- Sold out Label for variable products which are partially sold out
- wp_query ‘s’ parameter does not work with WC_AJAX