0

I want to display a popup by CodeLights on every WC product. For this I put this in my child theme's function.php

add_action( 'woocommerce_product_meta_end', 'childReview' );
function childReview() {
  echo do_shortcode('[cl-popup size="l" title="Click!" btn_label="Headline" btn_bgcolor="#006982" btn_color="#ffffff" overlay_bgcolor="rgba(0,105,130,0.75)" title_textcolor="#006982" content_textcolor="#006982"]Some Content goes here
[/cl-popup]');
}

This works absolutely fine. Now I want to add the product's image to each popup. What I tried is to put this into the content part of the shortcode, so behind "Some content goes here":

<img src="<?php the_post_thumbnail_url(); ?>" alt="" width="300" height="300" />

Unfortunately, that doesn't work at all. The popup works but the images src just remains as <?php the_post_thumbnail_url(); ?>, so the image doesn't appear.

Does anyone have some advice for me?

Thanks a lot and BR, Dario

1 Answer 1

1

I think you're just printing your function as a string, try concatonating:

add_action( 'woocommerce_product_meta_end', 'childReview' );
function childReview() {

  global $post;

  echo do_shortcode('[cl-popup size="l" title="Click!" btn_label="Headline" btn_bgcolor="#006982" btn_color="#ffffff" overlay_bgcolor="rgba(0,105,130,0.75)" title_textcolor="#006982" content_textcolor="#006982"]<img src=" ' . wp_get_attachment_url ( get_post_thumbnail_id( $post->ID ) ) . '"/>
[/cl-popup]');
}
11
  • Hi @MrBizle, thanks for your answer. I got a step further with it: the URL of the thumbnail is now being displayed. But not in the popup but before the generated button. And it's a URL that is being diplayed, not the image... Commented Aug 8, 2016 at 14:19
  • Cool! Are you sure you can put HTML in that shortcode? Sounds like might be stripping it out. Have you got a link bud? Commented Aug 8, 2016 at 14:23
  • Hi @MrBizle, hum, I'm sure that I can use HTML in that shortcode. Images, Headlines,... no problem. Not sure about PHP though...You can find the blue button with popup here: wohngeschwister.de/produkt/bowl-nor-blau. The generated URL appears above the button. Thank you so much for helping! Commented Aug 8, 2016 at 14:26
  • It doesn't appear to be rendering the src URL at all 🤔 Commented Aug 8, 2016 at 14:30
  • 1
    the_post_thumbnail_url doesn't take a post ID as the parameter. Try wp_get_attachment_url ( get_post_thumbnail_id( $post->ID ) ) instead. Commented Aug 8, 2016 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.