-
AuthorPosts
-
March 22, 2022 at 2:42 pm #1345534
Hello, please go to https://www.caspersmeets.nl/product/maxisys-ms906s/
I would like to add a second button right next to the original ‘Toevoegen aan winkelwagen’ button. This button has to be redirected to another specific page on the website. Is this possible?
Thanks!March 23, 2022 at 2:23 am #1345602Hey EricSmeets,
I assume that you want this button on every product page and it will lead to the same specific page.
Try adding this code to the end of your functions.php file in Appearance ▸ Editor:function custom_button_next_to_product_button() { ?> <script> (function($){ $('.single-product .single-product-summary').each(function() { $('<button class="button buttonLink">Een andere specifieke pagina</button>').insertAfter('.single_add_to_cart_button').css({ 'margin-left': '3%' }); }); $('.buttonLink').click(function(e){ e.preventDefault(); window.location.href = "https://google.com"; }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_button_next_to_product_button');
then adjust the link to suit.
Best regards,
MikeApril 4, 2022 at 3:09 pm #1347155Hello Mike,
thanks a lot. It works perfectly. However I don’t want it for every product. Is it possible to pick specific items for this function? How would this work?
Kind regards, Eric Smeets.
April 5, 2022 at 1:19 am #1347203Hi,
Glad to hear, to use this on only a specific product you can add the page ID to the .single-product class in the function, for example this product page you linked to above would be .postid-1365.single-product
If it is for multiple products and you have a list of page IDs then I could adjust the script, how many do you expect there to be, and do you feel that you could add and remove the page IDs to the script as you needed?
Do all of these have something in common like the same category?Best regards,
MikeApril 5, 2022 at 11:32 pm #1347333Yes, I understand what you mean and have altered the code to my needs. One question remains.
How would I alter the code if I want all the products in the category named ‘MaxiSys’ to have this extra button?April 6, 2022 at 10:02 am #1347383 -
AuthorPosts
- You must be logged in to reply to this topic.