Support

Account

Home Forums General Issues Get field from woocommerce attribute taxonomy

Solved

Get field from woocommerce attribute taxonomy

  • Hi,

    I’m trying to get a custom field “synonyms” that I have crated for the woocommerce attribute taxonomy, but it not returns the custom value.
    What I do wrong?

    The get:
    get_field('synonyms', $term->taxonomy . '_' . $term->term_id);

    My full code:

    
    $attribute_taxonomies = wc_get_attribute_taxonomies();
    if ( $attribute_taxonomies )
    {
    	foreach ($attribute_taxonomies as $tax)
    	{
    		if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name)))
    		{
    			/** The taxonomy we want to parse */
    			$taxonomy = wc_attribute_taxonomy_name($tax->attribute_name);
    			
    			/** Get all taxonomy terms */
    			$terms = get_terms($taxonomy, 
    				array(
    					'orderby'    => 'name',
    					'order'      => 'ASC',
    					"hide_empty" => false
    				)
    			);
    
    			/** Loop through every term */
    			foreach($terms as $term)
    			{
    				$synonyms = get_field('synonyms', $term->taxonomy . '_' . $term->term_id);
    				print $synonyms; 
    			}
    		}
    	}
    }
  • Hi @sergsce

    Could you please make sure that $term->taxonomy returns the right attribute slug? Could you please test it out by providing the ID manually like this:

    get_field('synonyms', 'pa_attributeslug_99');

    Where “pa_attributeslug” is the attribute slug and 99 is the ID of the term.

    Thanks!

  • I edited now one attribute term and its started work for all. I don’t know what was the problem and I refreshed the page by ctrl+F5 without changes.

  • Hi @sergsce

    So the issue is solved? If not, could you please tell me what’s wrong with it now?

    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Get field from woocommerce attribute taxonomy’ is closed to new replies.