Support

Account

Home Forums Front-end Issues Get field data in WooCommerce

Solved

Get field data in WooCommerce

  • Hi guys,

    I’m trying to display the URL of a wooCommerce category taxonomy but am getting a fatal error.

    I’m using..

    Field type taxonomy
    Taxonomy product_cat
    Return value Term object

    This is inside a repeater..
    <?php echo the_sub_field('category_button_url'); ?>

    The error..

    Catchable fatal error: Object of class WP_Term could not be converted to string in /Applications/XAMPP/xamppfiles/htdocs/r-com-website/wp-content/plugins/advanced-custom-fields/core/api.php on line 690

    Thank you!

  • Hi @klevermedia

    You can’t echo the_sub_field() function as it already echoing it’s value by itself. Also, you can’t echo a Taxonomy field because it is an object, not a string. I think you can do it like this:

    $theTerms = get_sub_field('category_button_url');
    echo get_term_link( $theTerms );

    This page should give you more idea about it: http://www.advancedcustomfields.com/resources/taxonomy/.

    I hope this helps.

  • Awesome, that’s just what I needed. Thank you for your help!

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

The topic ‘Get field data in WooCommerce’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.