Reputation: 1
Ok first post here, I am a bit of a noob when it comes to this sort of thing. So apologies if the answer is easy.
I am trying create a link and echo a custom URL plus also grab the current ID of that product. I have the link working but having trouble adding wc_get_page_id after ?add-to-cart=
echo '<a href="/basket/?add-to-cart=52&quantity=12">MY CUSTOM LINK</a>';
I have tried numerous ways to do this but none are working. any tips would be greatly appreciated.
Upvotes: 0
Views: 127
Reputation: 637
Welcome to SO. Because of your title I think you are trying to get product_id in a page that only one product is shown. But in reference of wc_get_page_id
it is said that
Retrieve page ids - used for myaccount, edit_address, shop, cart, checkout, pay, view_order, terms. returns -1 if no page is found.
So I think, this doesn't work for your case. If you want to get product id in the product page this question is related and you can do:
global $product;
$id = $product->get_id();
Upvotes: 1