Reply 334113 to: what .php file to edit if I wanto add acf field?

Avatar: Rose Tyler
Rose Tyler
Support staff
September 15, 2022 at 07:08

Hello,

We added next php snippet to your child-theme/functions.php ( https://prnt.sc/Wx7UJoZ5NxVx )

add_action('init', function() {
add_action( 'woocommerce_single_product_summary', function() {
global $product;
if ( function_exists('get_field')) {
$value = get_field( 'povezava_na_izdelek', $product->get_id() );
if ( $value ) { ?>
<a href="<?php echo esc_url($value); ?>" target="_blank"><?php esc_html_e('Povezava na izdelek', 'xstore-chid'); ?></a>
<?php }
}
}, 55);
}, 70);

Single product page -> https://prnt.sc/0iqrIoSnxdkk

We made link to open in new window but if you need to open it in current window you may change target=”_blank” to target=”_self”.
All attributes of a tag -> https://www.w3schools.com/tags/tag_a.asp

If you need to show the own product’s link on each product then there could be better to use next snippet without extra backend working process by adding own link on each product

add_action('init', function() {
add_action( 'woocommerce_single_product_summary', function() {
global $product;
?>
<a href="<?php the_permalink(); ?>" target="_blank"><?php esc_html_e('Povezava na izdelek', 'xstore-chid'); ?></a>
<?php
}, 55);
}, 70);

// It will add a link of the current product for all products

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.