Skip Navigation

[Resolved] Get the value of a custom field of a WooCommerce product

This thread is resolved. Here is a description of the problem and solution.

Problem:
Get the value of a custom field of a WooCommerce variable product (in the xml file generated by Google Product Feed).

Solution:
Please make sure to first add variations for the Variable product. And use the code and solution given here:
https://toolset.com/forums/topic/get-the-value-of-a-custom-field-of-a-woocommerce-product/page/2/#post-577980

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 19 replies, has 3 voices.

Last updated by kristofG 7 years, 1 month ago.

Assisted by: Noman.

Author
Posts
#577980

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Variable product.png
Simple product.png

I managed to get the Variable product ID and change the Title of products through a custom field in WooCommerce Google Product feed plugin -- please see attached screenshots.

- And it works for both types of products: Simple products and Variable products.

- Here is the code I have used:

function lw_woocommerce_gpf_title( $title, $product_id ) {
	
	$post_id = wp_get_post_parent_id( $product_id );
	if($post_id == 0)
		$post_id = $product_id;
	
    return get_post_meta( $post_id, 'wpcf-google-merchant-product-title', true);
}
add_filter( 'woocommerce_gpf_title', 'lw_woocommerce_gpf_title', 10, 2 );

Simple product: hidden link
Variable product: hidden link

I hope this resolves the issue. Thank you

#578182

This is amazing. I would have never thought that we needed the parent_id from the product_id

#578199

I might have closed it too early, there is an obsolete space in the

<![CDATA[
Kattenluik Felix | Ook geschikt voor kleine honden | Tomsgates
]]>

so Google Merchant Center thinks the title is empty.

UPDATE: skip the above comment, it was just Google that needed some more time to read the titles.

#578200

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Ok thanks for the update. I believe that its resolved now but I will wait for your confirmation. For now I am setting ticket status as "Waiting".

Thank you and have a great day.

#578932

issue fixed