• Resolved fmunozn

    (@fmunozn)


    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 4 years, 7 months ago by fmunozn.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author artiosmedia

    (@artiosmedia)

    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

    (@fmunozn)

    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

    (@artiosmedia)

    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!

    Hello @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

    (@fmunozn)

    Hello @westerndeal @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

    (@artiosmedia)

    @fmunozn Please kindly leave a review for the developers quick and accurate response and no fees charged: https://www.ads-software.com/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.