Title: Shortcode challenge
Last modified: August 19, 2016

---

# Shortcode challenge

 *  [dnboxster](https://wordpress.org/support/users/dnboxster/)
 * (@dnboxster)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/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.

## Tags

 * [add_shortcode](https://wordpress.org/support/topic-tag/add_shortcode/)
 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [do_shortcode](https://wordpress.org/support/topic-tag/do_shortcode/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [dnboxster](https://wordpress.org/support/users/dnboxster/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/shortcode-challenge/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
