Shortcode challenge
-
Hi,
I am trying to write a shortcode, [addtocart] in this instance, to get custom field template values inserted into the “add to cart” shortcode. The following code displays this text in my post :
[wp_cart:#4050 – TEST :price:9.99 :var1[Color| Blue | Green | Yellow ]:end]
Which is the exact expression I would like to be interpreted as a shortcode. In fact, if I copy/paste this expression into the post editor, it displays the output correctly (dropdown box with colors and a “add to cart” button).
What return value should I use to have my shortcode translated?
function addtocart_shortcode() { $prodtitle = __(single_post_title( '', false )); $prodid = do_shortcode('[cft key=Id]'); $prodprice = do_shortcode('[cft key=Prix]'); $prodcol = do_shortcode('[cft key=Colors]'); $prodbuy = '[wp_cart:#'.$prodid.' - '.$prodtitle.' '.':price:'. $prodprice.':var1[Color| '.$prodcol.' ]:end]'; return do_shortcode($prodbuy); } add_shortcode( 'addtocart', 'addtocart_shortcode' );
- The topic ‘Shortcode challenge’ is closed to new replies.