Title: Short code
Last modified: April 2, 2020

---

# Short code

 *  Resolved [fmunozn](https://wordpress.org/support/users/fmunozn/)
 * (@fmunozn)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/)
 * Hello
 * I try to create a short code to use in the detail of product in store and categories
 * i try the following:
 *     ```
       function codenew_shortcode_de_contenido() {
           global $product;
           echo 'CODE: ' . $product->get_product_code();
        }
        add_shortcode('codenew', 'codenew_shortcode_de_contenido'); 
       ```
   
 * I use it as [codenew] and it generates an error. does not show the product code.
 * Could someone help me please excuse the inconvenience I’m not an expert, thanks
    -  This topic was modified 6 years, 1 month ago by [fmunozn](https://wordpress.org/support/users/fmunozn/).

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [artiosmedia](https://wordpress.org/support/users/artiosmedia/)
 * (@artiosmedia)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12620837)
 * Your request was seen 2 hours after your posting. I have asked the developer 
   to respond to this inquiry. His response may be delayed. Thanks.
 *  Thread Starter [fmunozn](https://wordpress.org/support/users/fmunozn/)
 * (@fmunozn)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12623765)
 * I thank you, I only need that to finish the project if you have to charge me 
   something for this no problem contact me
 * Thank you, I await your response
 *  Plugin Author [artiosmedia](https://wordpress.org/support/users/artiosmedia/)
 * (@artiosmedia)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12625450)
 * Even if you paid us, there would still be a waiting period. It takes up to four
   weeks for simple changes. I am at the mercy of the developers and they are exceedingly
   slow. Sorry!
 *  [WesternDeal](https://wordpress.org/support/users/westerndeal/)
 * (@westerndeal)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12626877)
 * Hello [@fmunozn](https://wordpress.org/support/users/fmunozn/),
 * Sorry for the delay in responding due to different timezone, I always tried best
   to answer as soon as possible.
 * As you know that the “Product Code for WooCommerce” is an add-on the Product 
   Code can not be fetched via a woocommerce inbuilt product functions. Also, there
   is no function like get_product_code() which you are using. So obviously it will
   show an error.
 * Product Code data are saved as a meta key and value to the “postmeta” table of
   WordPress.
    To get it displayed for your custom code you can use the following
   snippet.
 *     ```
       function product_code_shortcode() {
          global $product;
          if( $product ) {
             $product_id = $product->get_id();
             // Check if product is variable product type
             if( $product->is_type( 'variable' ) ){
                //get all variation list
                $variations = $product->get_available_variations();
                if( $variations ) {
                   foreach( $variations as $variable_product ) {
                      $value = get_post_meta( $variable_product['variation_id'], "_product_code_variant", true );
                      $code = !$value ? __( 'N/A', 'product-code-for-woocommerce' ) : $value;
                      echo 'CODE: ' . $code . '<br/>';
                   }
                }        
             } else {      
                $value = get_post_meta( $product_id, "_product_code", true );
                $code = !$value ? __( 'N/A', 'product-code-for-woocommerce' ) : $value;
                echo 'CODE: ' . $code;
             }
          }
        }
        add_shortcode('codenew', 'product_code_shortcode'); 
       ```
   
 * Hope my answer helps you. Let me know further.
 * Thanks
    Abdullah
 *  Thread Starter [fmunozn](https://wordpress.org/support/users/fmunozn/)
 * (@fmunozn)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12632744)
 * Hello [@westerndeal](https://wordpress.org/support/users/westerndeal/) [@artiosmedia](https://wordpress.org/support/users/artiosmedia/)
 * it worked perfect I appreciate your help.
 * You could add it to the frequently asked questions, I think it is super useful,
   I congratulate you for the development, it helped me a lot in my project, thank
   you.
 * from Chile.
 *  Plugin Author [artiosmedia](https://wordpress.org/support/users/artiosmedia/)
 * (@artiosmedia)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12632891)
 * [@fmunozn](https://wordpress.org/support/users/fmunozn/) Please kindly leave 
   a review for the developers quick and accurate response and no fees charged: 
   [https://wordpress.org/support/plugin/product-code-for-woocommerce/reviews/](https://wordpress.org/support/plugin/product-code-for-woocommerce/reviews/)
 * I married a Chilean lady from Temuco in 2010 🙂 Wonderful people.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Short code’ is closed to new replies.

 * ![](https://ps.w.org/product-code-for-woocommerce/assets/icon-256x256.jpg?rev
   =2019765)
 * [Product Code for WooCommerce](https://wordpress.org/plugins/product-code-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/product-code-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/product-code-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/product-code-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/product-code-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/product-code-for-woocommerce/reviews/)

## Tags

 * [product code](https://wordpress.org/support/topic-tag/product-code/)
 * [Short Code](https://wordpress.org/support/topic-tag/short-code/)

 * 6 replies
 * 3 participants
 * Last reply from: [artiosmedia](https://wordpress.org/support/users/artiosmedia/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/short-code-131/#post-12632891)
 * Status: resolved