Title: Simple custom shortcode problem
Last modified: August 21, 2016

---

# Simple custom shortcode problem

 *  [lochie1979](https://wordpress.org/support/users/lochie1979/)
 * (@lochie1979)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/simple-custom-shortcode-problem/)
 * I have the following custom shortcode code which I put into my theme functions.
   php file (I was given this code). It is just to help me get a list of product
   names with a cost for every product under a specific category. Example: PRODUCT
   NAME $X.XX. Each product would be on a new line. This is working out fine, but
   when I use the short code to put this on a page, I put the shortcode UNDER text
   I want on the page, but the shortcode ALWAYS shows it ABOVE the text rather than
   UNDER which is where I put the shortcode and expected the out put to be?
 * I also found that it doesn’t show the currency symbol, but shows USD instead?
 *     ```
       function product_list_by_category_name( $product_category_name ){
       	$args = array( 'post_type' => 'product', 'product_cat' => $product_category_name );
   
           $loop = new WP_Query( $args );
   
           while ( $loop->have_posts() ) : $loop->the_post();
           global $product; 
   
       	$amount = get_post_meta($product->post->ID, '_price', true) . ' ' . get_woocommerce_currency();
   
       	echo '<a href="'.get_permalink().'">'. get_the_title() .'</a> '. $amount .'<br />';
   
           endwhile; 
   
           wp_reset_query();
       }
   
       /** SHORTCODE **/
       function product_list_by_category_name_shortcode( $atts ) {
       	extract(shortcode_atts(array(
       		'product_category_slug' => ''
       	), $atts));
   
       	return product_list_by_category_name( $product_category_slug );
       }
   
       add_shortcode( 'product_list_by_category', 'product_list_by_category_name_shortcode' );
       ```
   
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [lochie1979](https://wordpress.org/support/users/lochie1979/)
 * (@lochie1979)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/simple-custom-shortcode-problem/#post-5153497)
 * still same issue but latest version of the code is:
 *     ```
       function product_list_by_category_name( $product_category_name ){
               $args = array( 'post_type' => 'product', 'product_cat' => $product_category_name );
   
           $loop = new WP_Query( $args );
   
           while ( $loop->have_posts() ) : $loop->the_post();
           global $product;
   
               $amount = get_post_meta($product->post->ID, '_price', true) . ' ' . get_woocommerce_currency();
              echo '<table width="400" border="0" cellspacing="0" cellpadding="2">';
               echo '<tr><td width="250"><div align="left"><!-- <a href="'.get_permalink().'"> --!>'. get_the_title() .'<!-- </a> --!></div></td><td width="150"><div align="left"> '. $amount .'</div></td></tr>';
        echo '</table>';
           endwhile;
   
           wp_reset_query();
   
       }
   
       /** SHORTCODE **/
       function product_list_by_category_name_shortcode( $atts ) {
               extract(shortcode_atts(array(
                       'product_category_slug' => ''
               ), $atts));
   
               return product_list_by_category_name( $product_category_slug );
       }
   
       add_shortcode( 'product_list_by_category', 'product_list_by_category_name_shortcode' );
   
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Simple custom shortcode problem’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 1 reply
 * 1 participant
 * Last reply from: [lochie1979](https://wordpress.org/support/users/lochie1979/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/simple-custom-shortcode-problem/#post-5153497)
 * Status: not resolved