Hi, I’m hoping someone can assist me or point me in the right direction. I have a product template in WooCommerce – each product page has a few links that take the users to a customization. Since all of the products will follow the same URL structure, I’m hoping to add a custom field to the template. For example, I’m hoping to create a custom field called “State URL” so on the page links utilize the custom field to customize the link.
Each WooCommerce product would have a custom field.
Custom Field = “state_url”
Link would https://domain/product/STATE_URL-productname
Essentially, all the products share the same template, so I’m hoping to utilize the custom field to generate the link the customer will click on rather than having to customize each page on its own.
What code should I enter into the href code? Do I also need to add something to functions.php?
THANKS!
Hi @pmmg
I think I’d be inclined to do something like:
$current_url = get_permalink();
$state_url = get_field('state_url');
$product = get_title();
echo '<a href="$current_url.$state_url.'-'.$product">Link</a>';
Or
$site_url = get_site_url();
$state_url = get_field('state_url');
$product = get_title();
echo '<a href="$site_url.'/product/'.$state_url.'-'.$product">Link</a>';
May need a little tweaking but should get you underway!