Add Custom fields values to Woocommerce email notification





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
I need to show this fields on the email sent by woocommerce.



this is the way , the fields from checkout are being displayed on the email template:



<?php if ( $order->get_billing_first_name() ) : ?>
<br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
<?php endif; ?>


<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
<?php endif; ?>

<?php if ( $order->get_billing_company() ) : ?>
<br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
<?php endif; ?>

<?php if ( $order->get_billing_address_1() ) : ?>
<br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
<?php endif; ?>

<?php if ( $order->get_billing_address_2() ) : ?>
<br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
<?php endif; ?>

<?php if ( $order->get_billing_city() ) : ?>
<br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
<?php endif; ?>


I need to show the new 2 custom fields as well but there's no method for



$order->get_customfield1()









share|improve this question































    1















    I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
    I need to show this fields on the email sent by woocommerce.



    this is the way , the fields from checkout are being displayed on the email template:



    <?php if ( $order->get_billing_first_name() ) : ?>
    <br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
    <?php endif; ?>


    <?php if ( $order->get_billing_phone() ) : ?>
    <br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
    <?php endif; ?>

    <?php if ( $order->get_billing_company() ) : ?>
    <br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
    <?php endif; ?>

    <?php if ( $order->get_billing_address_1() ) : ?>
    <br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
    <?php endif; ?>

    <?php if ( $order->get_billing_address_2() ) : ?>
    <br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
    <?php endif; ?>

    <?php if ( $order->get_billing_city() ) : ?>
    <br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
    <?php endif; ?>


    I need to show the new 2 custom fields as well but there's no method for



    $order->get_customfield1()









    share|improve this question



























      1












      1








      1








      I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
      I need to show this fields on the email sent by woocommerce.



      this is the way , the fields from checkout are being displayed on the email template:



      <?php if ( $order->get_billing_first_name() ) : ?>
      <br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
      <?php endif; ?>


      <?php if ( $order->get_billing_phone() ) : ?>
      <br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_company() ) : ?>
      <br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_address_1() ) : ?>
      <br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_address_2() ) : ?>
      <br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_city() ) : ?>
      <br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
      <?php endif; ?>


      I need to show the new 2 custom fields as well but there's no method for



      $order->get_customfield1()









      share|improve this question
















      I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
      I need to show this fields on the email sent by woocommerce.



      this is the way , the fields from checkout are being displayed on the email template:



      <?php if ( $order->get_billing_first_name() ) : ?>
      <br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
      <?php endif; ?>


      <?php if ( $order->get_billing_phone() ) : ?>
      <br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_company() ) : ?>
      <br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_address_1() ) : ?>
      <br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_address_2() ) : ?>
      <br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
      <?php endif; ?>

      <?php if ( $order->get_billing_city() ) : ?>
      <br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
      <?php endif; ?>


      I need to show the new 2 custom fields as well but there's no method for



      $order->get_customfield1()






      php wordpress woocommerce custom-fields orders






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 1:51









      LoicTheAztec

      98.3k1472114




      98.3k1472114










      asked Nov 22 '18 at 15:00









      Claudio MartinezClaudio Martinez

      337




      337
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Since Woocommerce 3, there is a method inherited from WC_Data Class which is get_meta() and that has to be used on the WC_Order $order instance object.




          Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in wp_postmeta table.

          So I will use: _billing_customfield1 and _billing_customfield2




          Here is your revisited code:



          <?php 
          if ( $order->get_formatted_billing_full_name() ) {
          echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
          }
          if ( $order->get_billing_phone() ) {
          echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
          }
          if ( $order->get_billing_company() ) {
          echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
          }
          if ( $order->get_billing_address_1() ) {
          echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
          }
          if ( $order->get_billing_address_2() ) {
          echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
          }
          if ( $order->get_billing_city() ) {
          echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
          }
          if ( $order->get_meta('_billing_customfield1') ) {
          echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
          }
          if ( $order->get_meta('_billing_customfield2') ) {
          echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
          }
          ?>


          It should works if those custom fields slugs are _billing_customfield1 and _billing_customfield2



          You should need to verify in your database under wp_postmeta table that the correct meta_key are _billing_customfield1 and _billing_customfield2



          If not you will replace them with the right ones.





          You can also use the WordPress get_post_meta() function that needs the Order ID that you can have with $order->get_id() like:



          if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
          echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
          }
          if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
          echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
          }





          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%2f53433640%2fadd-custom-fields-values-to-woocommerce-email-notification%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Since Woocommerce 3, there is a method inherited from WC_Data Class which is get_meta() and that has to be used on the WC_Order $order instance object.




            Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in wp_postmeta table.

            So I will use: _billing_customfield1 and _billing_customfield2




            Here is your revisited code:



            <?php 
            if ( $order->get_formatted_billing_full_name() ) {
            echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
            }
            if ( $order->get_billing_phone() ) {
            echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
            }
            if ( $order->get_billing_company() ) {
            echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
            }
            if ( $order->get_billing_address_1() ) {
            echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
            }
            if ( $order->get_billing_address_2() ) {
            echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
            }
            if ( $order->get_billing_city() ) {
            echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
            }
            if ( $order->get_meta('_billing_customfield1') ) {
            echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
            }
            if ( $order->get_meta('_billing_customfield2') ) {
            echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
            }
            ?>


            It should works if those custom fields slugs are _billing_customfield1 and _billing_customfield2



            You should need to verify in your database under wp_postmeta table that the correct meta_key are _billing_customfield1 and _billing_customfield2



            If not you will replace them with the right ones.





            You can also use the WordPress get_post_meta() function that needs the Order ID that you can have with $order->get_id() like:



            if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
            echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
            }
            if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
            echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
            }





            share|improve this answer






























              1














              Since Woocommerce 3, there is a method inherited from WC_Data Class which is get_meta() and that has to be used on the WC_Order $order instance object.




              Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in wp_postmeta table.

              So I will use: _billing_customfield1 and _billing_customfield2




              Here is your revisited code:



              <?php 
              if ( $order->get_formatted_billing_full_name() ) {
              echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
              }
              if ( $order->get_billing_phone() ) {
              echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
              }
              if ( $order->get_billing_company() ) {
              echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
              }
              if ( $order->get_billing_address_1() ) {
              echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
              }
              if ( $order->get_billing_address_2() ) {
              echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
              }
              if ( $order->get_billing_city() ) {
              echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
              }
              if ( $order->get_meta('_billing_customfield1') ) {
              echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
              }
              if ( $order->get_meta('_billing_customfield2') ) {
              echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
              }
              ?>


              It should works if those custom fields slugs are _billing_customfield1 and _billing_customfield2



              You should need to verify in your database under wp_postmeta table that the correct meta_key are _billing_customfield1 and _billing_customfield2



              If not you will replace them with the right ones.





              You can also use the WordPress get_post_meta() function that needs the Order ID that you can have with $order->get_id() like:



              if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
              echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
              }
              if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
              echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
              }





              share|improve this answer




























                1












                1








                1







                Since Woocommerce 3, there is a method inherited from WC_Data Class which is get_meta() and that has to be used on the WC_Order $order instance object.




                Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in wp_postmeta table.

                So I will use: _billing_customfield1 and _billing_customfield2




                Here is your revisited code:



                <?php 
                if ( $order->get_formatted_billing_full_name() ) {
                echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
                }
                if ( $order->get_billing_phone() ) {
                echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
                }
                if ( $order->get_billing_company() ) {
                echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
                }
                if ( $order->get_billing_address_1() ) {
                echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
                }
                if ( $order->get_billing_address_2() ) {
                echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
                }
                if ( $order->get_billing_city() ) {
                echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
                }
                if ( $order->get_meta('_billing_customfield1') ) {
                echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
                }
                if ( $order->get_meta('_billing_customfield2') ) {
                echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
                }
                ?>


                It should works if those custom fields slugs are _billing_customfield1 and _billing_customfield2



                You should need to verify in your database under wp_postmeta table that the correct meta_key are _billing_customfield1 and _billing_customfield2



                If not you will replace them with the right ones.





                You can also use the WordPress get_post_meta() function that needs the Order ID that you can have with $order->get_id() like:



                if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
                echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
                }
                if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
                echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
                }





                share|improve this answer















                Since Woocommerce 3, there is a method inherited from WC_Data Class which is get_meta() and that has to be used on the WC_Order $order instance object.




                Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in wp_postmeta table.

                So I will use: _billing_customfield1 and _billing_customfield2




                Here is your revisited code:



                <?php 
                if ( $order->get_formatted_billing_full_name() ) {
                echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
                }
                if ( $order->get_billing_phone() ) {
                echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
                }
                if ( $order->get_billing_company() ) {
                echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
                }
                if ( $order->get_billing_address_1() ) {
                echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
                }
                if ( $order->get_billing_address_2() ) {
                echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
                }
                if ( $order->get_billing_city() ) {
                echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
                }
                if ( $order->get_meta('_billing_customfield1') ) {
                echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
                }
                if ( $order->get_meta('_billing_customfield2') ) {
                echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
                }
                ?>


                It should works if those custom fields slugs are _billing_customfield1 and _billing_customfield2



                You should need to verify in your database under wp_postmeta table that the correct meta_key are _billing_customfield1 and _billing_customfield2



                If not you will replace them with the right ones.





                You can also use the WordPress get_post_meta() function that needs the Order ID that you can have with $order->get_id() like:



                if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
                echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
                }
                if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
                echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 '18 at 1:48

























                answered Nov 23 '18 at 1:43









                LoicTheAztecLoicTheAztec

                98.3k1472114




                98.3k1472114
































                    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%2f53433640%2fadd-custom-fields-values-to-woocommerce-email-notification%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

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?