Support

Account

Home Forums Front-end Issues Adding a around the_field in functions.php

Solved

Adding a around the_field in functions.php

  • I’ve just added a new custom field, called Country of Origin, I’ve been able to use the following in my functions.php file to call the country of origin below each product on the shop page. It works fine, the only issue is I can’t get the actual the_field(‘country_of_origin’) wrapped in a div with a specific CSS class attached to it, so that I can style it. Not sure what the best way to move forward with this would be as I’m fairly new to php.

    <?php
    	/ Add ACF Info to Product on Shop page
     	add_action( 'woocommerce_after_shop_loop_item_title', "ACF_product_content", 10 );
    
     	function ACF_product_content(){
    
    		if (function_exists('the_field')){
       			echo ‘Country of Origin: 
    ';
    
     	 		the_field('country_of_origin');
     		}
       	}
    ?>

    Edit: Figured it out, was such an easy fix, can’t believe I didn’t think of it before!!

    Just had to echo <divs> around the_field()

Viewing 1 post (of 1 total)

The topic ‘Adding a around the_field in functions.php’ is closed to new replies.