On my webshop I have to see a button with a link to ad pdf file. For every product that button need to have a different link and a different button title name.

I built the webshop with woocommerce where I used Advanced Custom fields to show the buttons with a pdf link. In ACF I used a link array. On the product page I can change the title text of the link manually.

But. There are more than 1000 products. So it's not possible to do this manually. I imported a csv with the right header names. And importing the columns with links to the buttons works properly.

In the php code I used this standard acf code:

$link = get_field('link');
if( $link ): 
    $link_url = $link['url'];
    $link_title = $link['title'];
    $link_target = $link['target'] ? $link['target'] : '_self';
    <a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
<?php endif; ?>

So, what meta data I have to give in my csv file to fill in the link title? --> The title on the button.


If you make a var_dump() on $link:

var_dump('<pre>', $link);

then you will see all array keys and you can choose the one you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.