Allow shortcodes in product variations description in Woocommerce












2















I would like to use a pods shortcode field inside the woocommerce variable product description but by default the variable description field does not support shortcodes.



The variation description is stored in an array woocommerce_available_variation, so I can't simple call the function do_shortcode($variation).



I am trying to allow short codes in this field by using the below code:



add_filter( 'woocommerce_available_variation', 'shortcode_variation_description');

function shortcode_variation_description( $variation ) {
$variation['variation_description'] = do_shortcode( $variation['variation_description'] );
return $variation;


But it's not working.



Anybody to figure out what I am doing wrong?










share|improve this question





























    2















    I would like to use a pods shortcode field inside the woocommerce variable product description but by default the variable description field does not support shortcodes.



    The variation description is stored in an array woocommerce_available_variation, so I can't simple call the function do_shortcode($variation).



    I am trying to allow short codes in this field by using the below code:



    add_filter( 'woocommerce_available_variation', 'shortcode_variation_description');

    function shortcode_variation_description( $variation ) {
    $variation['variation_description'] = do_shortcode( $variation['variation_description'] );
    return $variation;


    But it's not working.



    Anybody to figure out what I am doing wrong?










    share|improve this question



























      2












      2








      2








      I would like to use a pods shortcode field inside the woocommerce variable product description but by default the variable description field does not support shortcodes.



      The variation description is stored in an array woocommerce_available_variation, so I can't simple call the function do_shortcode($variation).



      I am trying to allow short codes in this field by using the below code:



      add_filter( 'woocommerce_available_variation', 'shortcode_variation_description');

      function shortcode_variation_description( $variation ) {
      $variation['variation_description'] = do_shortcode( $variation['variation_description'] );
      return $variation;


      But it's not working.



      Anybody to figure out what I am doing wrong?










      share|improve this question
















      I would like to use a pods shortcode field inside the woocommerce variable product description but by default the variable description field does not support shortcodes.



      The variation description is stored in an array woocommerce_available_variation, so I can't simple call the function do_shortcode($variation).



      I am trying to allow short codes in this field by using the below code:



      add_filter( 'woocommerce_available_variation', 'shortcode_variation_description');

      function shortcode_variation_description( $variation ) {
      $variation['variation_description'] = do_shortcode( $variation['variation_description'] );
      return $variation;


      But it's not working.



      Anybody to figure out what I am doing wrong?







      php wordpress woocommerce shortcode variations






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 7:50









      LoicTheAztec

      87.9k1364101




      87.9k1364101










      asked Nov 14 '18 at 6:09









      JakedeJakede

      132




      132
























          2 Answers
          2






          active

          oldest

          votes


















          1














          When using your code, it works. To test, I have used the Woocommerce shortcode [products] in a variation description as follow:



          The imputed text is (where 37 is a real simple product ID):
          "This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."



          And I get this display:



          enter image description here



          So it works for real. I have lightly made some little changes to this code version (yours work too):



          add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
          function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
          $variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );

          return $variation_data;
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.






          share|improve this answer





















          • 1





            Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

            – Jakede
            Nov 14 '18 at 8:15



















          0














          You can define your own shortcode, see the documentation. You can copy/paste the code because it's wrapped in a class so it won't trigger fatal error due to double declaration.



          But shortcode do not work that way :



          function shortcode_handler($atts) {
          //code goes here
          }
          add_shortcode("name_of_shortcode","shortcode_handler');





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294100%2fallow-shortcodes-in-product-variations-description-in-woocommerce%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            When using your code, it works. To test, I have used the Woocommerce shortcode [products] in a variation description as follow:



            The imputed text is (where 37 is a real simple product ID):
            "This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."



            And I get this display:



            enter image description here



            So it works for real. I have lightly made some little changes to this code version (yours work too):



            add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
            function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
            $variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );

            return $variation_data;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.






            share|improve this answer





















            • 1





              Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

              – Jakede
              Nov 14 '18 at 8:15
















            1














            When using your code, it works. To test, I have used the Woocommerce shortcode [products] in a variation description as follow:



            The imputed text is (where 37 is a real simple product ID):
            "This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."



            And I get this display:



            enter image description here



            So it works for real. I have lightly made some little changes to this code version (yours work too):



            add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
            function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
            $variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );

            return $variation_data;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.






            share|improve this answer





















            • 1





              Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

              – Jakede
              Nov 14 '18 at 8:15














            1












            1








            1







            When using your code, it works. To test, I have used the Woocommerce shortcode [products] in a variation description as follow:



            The imputed text is (where 37 is a real simple product ID):
            "This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."



            And I get this display:



            enter image description here



            So it works for real. I have lightly made some little changes to this code version (yours work too):



            add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
            function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
            $variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );

            return $variation_data;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.






            share|improve this answer















            When using your code, it works. To test, I have used the Woocommerce shortcode [products] in a variation description as follow:



            The imputed text is (where 37 is a real simple product ID):
            "This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."



            And I get this display:



            enter image description here



            So it works for real. I have lightly made some little changes to this code version (yours work too):



            add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
            function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
            $variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );

            return $variation_data;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 14:58

























            answered Nov 14 '18 at 7:49









            LoicTheAztecLoicTheAztec

            87.9k1364101




            87.9k1364101








            • 1





              Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

              – Jakede
              Nov 14 '18 at 8:15














            • 1





              Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

              – Jakede
              Nov 14 '18 at 8:15








            1




            1





            Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

            – Jakede
            Nov 14 '18 at 8:15





            Oh thanks a lot @LoicTheAztec. I implemented your code and now it works just fine! Mega thanks to you - i have been struggling with this issue for hours.

            – Jakede
            Nov 14 '18 at 8:15













            0














            You can define your own shortcode, see the documentation. You can copy/paste the code because it's wrapped in a class so it won't trigger fatal error due to double declaration.



            But shortcode do not work that way :



            function shortcode_handler($atts) {
            //code goes here
            }
            add_shortcode("name_of_shortcode","shortcode_handler');





            share|improve this answer




























              0














              You can define your own shortcode, see the documentation. You can copy/paste the code because it's wrapped in a class so it won't trigger fatal error due to double declaration.



              But shortcode do not work that way :



              function shortcode_handler($atts) {
              //code goes here
              }
              add_shortcode("name_of_shortcode","shortcode_handler');





              share|improve this answer


























                0












                0








                0







                You can define your own shortcode, see the documentation. You can copy/paste the code because it's wrapped in a class so it won't trigger fatal error due to double declaration.



                But shortcode do not work that way :



                function shortcode_handler($atts) {
                //code goes here
                }
                add_shortcode("name_of_shortcode","shortcode_handler');





                share|improve this answer













                You can define your own shortcode, see the documentation. You can copy/paste the code because it's wrapped in a class so it won't trigger fatal error due to double declaration.



                But shortcode do not work that way :



                function shortcode_handler($atts) {
                //code goes here
                }
                add_shortcode("name_of_shortcode","shortcode_handler');






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 8:32









                Harshit_RajHarshit_Raj

                967




                967






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294100%2fallow-shortcodes-in-product-variations-description-in-woocommerce%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values