- This topic has 28 replies, 3 voices, and was last updated 7 years, 3 months ago by
David.
-
AuthorPosts
-
February 28, 2019 at 8:23 am #824689
wonzilla
Hi Tom,
It doesn’t matter where I add the buttons. I tried with the
woocommerce_after_shop_loop_item_titleandwoocommerce_shop_loop_item_titlehooks but the issue persists. What do you mean with removing the span tags?February 28, 2019 at 9:22 am #824742Tom
Lead DeveloperLead DeveloperI mean doing something like this:
add_action( 'woocommerce_before_shop_loop_item_title', function() { $urlr = get_post_meta( get_the_ID(), 'product_demo_url', true ); if ($urlr) : ?> <a class="button demo-btn" href="<?php echo $urlr; ?>" target="_blank" rel="nofollow">View Demo</a> <?php endif; } );February 28, 2019 at 11:06 am #824824wonzilla
Sorry, I thought you were referring to the span tags with no content from my screenshot. I added the tags because I was hoping that this trick will solve this issue somehow. It makes no difference if I remove the span tags from my function :/ That’s really weird and I don’t know what I need to do. I don’t like to have html lines with hyperlinks with no content… that doesn’t look good from a SEO perspective either.
February 28, 2019 at 5:15 pm #825089Tom
Lead DeveloperLead DeveloperI wonder if it’s an issue with the hook.
What if you just did this?:
add_action( 'woocommerce_before_shop_loop_item_title', function() { $urlr = get_post_meta( get_the_ID(), 'product_demo_url', true ); if ($urlr) : ?> testing <?php endif; } );March 1, 2019 at 1:06 am #825300wonzilla
It works with text but doesn’t work with hyperlinks and I need to add the link. It’s not the first time I notice this behavior with links inside a function.
March 1, 2019 at 8:49 am #825768Tom
Lead DeveloperLead DeveloperThat means it’s likely an issue with the hook.
Maybe try
woocommerce_before_shop_loop_iteminstead?March 1, 2019 at 10:36 am #825864wonzilla
I tried it and it’s the same problem 🙁
March 1, 2019 at 3:20 pm #826056Tom
Lead DeveloperLead DeveloperI see the issue. That hook is already wrapped in a link, and you can’t add a link within a link.
You would have to do something like this:
add_action( 'woocommerce_before_shop_loop_item', function() { $urlr = get_post_meta( get_the_ID(), 'product_demo_url', true ); if ($urlr) : ?> <a class="button demo-btn" href="<?php echo $urlr; ?>" target="_blank" rel="nofollow">View Demo</a> <?php endif; }, 5 );March 1, 2019 at 3:37 pm #826062wonzilla
Oh god… you’re right with the link inside the link, lol!!! But I still want to add the button inside the
wc-product-imagewrapper because I want to show the button when I mouseover the product image (it should appear inside the product image). Do you have any idea how can I do this or move the link to wrap only the image (img tag)? Thank you and sorry for bugging you with so many questions!March 1, 2019 at 5:03 pm #826094Tom
Lead DeveloperLead DeveloperNot sure if this will work, but you can try moving the standard link:
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 100 );March 2, 2019 at 2:03 am #826292wonzilla
Hi Tom,
Thank you for the code but the link is still wrapping the
wc-product-imagecontainer.March 2, 2019 at 9:36 am #826673Tom
Lead DeveloperLead DeveloperAny chance you can link me to the page?
March 2, 2019 at 7:04 pm #826957wonzilla
Sorry but my site is under construction and I would prefer to leave it like that because I don’t want my visitors to see a total disaster. I’m not sure why it is necessary to see it, it’s the same theme and I didn’t make any major changes to it. Only css coding here and there…
I want the demo link to appear like on this theme http://demo.megathe.me/skylab/ (you can see the view demo button on the hero section).
March 3, 2019 at 4:45 am #827195David
StaffCustomer SupportHi there,
it’s rare that Tom asks for access to the site, which means it must be important for him to help you achieve your requirements. Would you be willing to provide us with temporary login ? If so you can share the details via the Account Issue form here:
https://generatepress.com/contact/
Please add the URL for this topic to the form so it can be tracked.
-
AuthorPosts
- You must be logged in to reply to this topic.