Add Applied Coupon Code in Admin New Order Email Template - WooCommerce












3















Let me clear my question:




  • I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.

  • I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.


Now:




  1. Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?

  2. Can you tell me how to call applied coupon code, so that i will display this in email template?


It would be great, if you help me please.










share|improve this question





























    3















    Let me clear my question:




    • I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.

    • I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.


    Now:




    1. Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?

    2. Can you tell me how to call applied coupon code, so that i will display this in email template?


    It would be great, if you help me please.










    share|improve this question



























      3












      3








      3


      3






      Let me clear my question:




      • I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.

      • I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.


      Now:




      1. Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?

      2. Can you tell me how to call applied coupon code, so that i will display this in email template?


      It would be great, if you help me please.










      share|improve this question
















      Let me clear my question:




      • I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.

      • I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.


      Now:




      1. Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?

      2. Can you tell me how to call applied coupon code, so that i will display this in email template?


      It would be great, if you help me please.







      php wordpress woocommerce coupon email-notifications






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '17 at 1:37









      LoicTheAztec

      95k1370110




      95k1370110










      asked Nov 16 '17 at 5:22









      Surabhi GuptaSurabhi Gupta

      367




      367
























          2 Answers
          2






          active

          oldest

          votes


















          3














          This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:



          // The email function hooked that display the text
          add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
          function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

          // Only for admins and when there at least 1 coupon in the order
          if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

          foreach( $order->get_items('coupon') as $coupon ){
          $coupon_codes = $coupon->get_code();
          }
          // For one coupon
          if( count($coupon_codes) == 1 ){
          $coupon_code = reset($coupon_codes);
          echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
          }
          // For multiple coupons
          else {
          $coupon_codes = implode( ', ', $coupon_codes);
          echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
          }
          }


          Code goes in function.php file of your active child theme (or theme) or also in any plugin file.



          Tested and works...






          share|improve this answer































            0














            This is because $coupon_codes is not an array() define it with $coupon_codes=array();






            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%2f47322228%2fadd-applied-coupon-code-in-admin-new-order-email-template-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









              3














              This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:



              // The email function hooked that display the text
              add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
              function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

              // Only for admins and when there at least 1 coupon in the order
              if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

              foreach( $order->get_items('coupon') as $coupon ){
              $coupon_codes = $coupon->get_code();
              }
              // For one coupon
              if( count($coupon_codes) == 1 ){
              $coupon_code = reset($coupon_codes);
              echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
              }
              // For multiple coupons
              else {
              $coupon_codes = implode( ', ', $coupon_codes);
              echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
              }
              }


              Code goes in function.php file of your active child theme (or theme) or also in any plugin file.



              Tested and works...






              share|improve this answer




























                3














                This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:



                // The email function hooked that display the text
                add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
                function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

                // Only for admins and when there at least 1 coupon in the order
                if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

                foreach( $order->get_items('coupon') as $coupon ){
                $coupon_codes = $coupon->get_code();
                }
                // For one coupon
                if( count($coupon_codes) == 1 ){
                $coupon_code = reset($coupon_codes);
                echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
                }
                // For multiple coupons
                else {
                $coupon_codes = implode( ', ', $coupon_codes);
                echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
                }
                }


                Code goes in function.php file of your active child theme (or theme) or also in any plugin file.



                Tested and works...






                share|improve this answer


























                  3












                  3








                  3







                  This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:



                  // The email function hooked that display the text
                  add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
                  function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

                  // Only for admins and when there at least 1 coupon in the order
                  if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

                  foreach( $order->get_items('coupon') as $coupon ){
                  $coupon_codes = $coupon->get_code();
                  }
                  // For one coupon
                  if( count($coupon_codes) == 1 ){
                  $coupon_code = reset($coupon_codes);
                  echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
                  }
                  // For multiple coupons
                  else {
                  $coupon_codes = implode( ', ', $coupon_codes);
                  echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
                  }
                  }


                  Code goes in function.php file of your active child theme (or theme) or also in any plugin file.



                  Tested and works...






                  share|improve this answer













                  This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:



                  // The email function hooked that display the text
                  add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
                  function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

                  // Only for admins and when there at least 1 coupon in the order
                  if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

                  foreach( $order->get_items('coupon') as $coupon ){
                  $coupon_codes = $coupon->get_code();
                  }
                  // For one coupon
                  if( count($coupon_codes) == 1 ){
                  $coupon_code = reset($coupon_codes);
                  echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
                  }
                  // For multiple coupons
                  else {
                  $coupon_codes = implode( ', ', $coupon_codes);
                  echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
                  }
                  }


                  Code goes in function.php file of your active child theme (or theme) or also in any plugin file.



                  Tested and works...







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 '17 at 1:35









                  LoicTheAztecLoicTheAztec

                  95k1370110




                  95k1370110

























                      0














                      This is because $coupon_codes is not an array() define it with $coupon_codes=array();






                      share|improve this answer




























                        0














                        This is because $coupon_codes is not an array() define it with $coupon_codes=array();






                        share|improve this answer


























                          0












                          0








                          0







                          This is because $coupon_codes is not an array() define it with $coupon_codes=array();






                          share|improve this answer













                          This is because $coupon_codes is not an array() define it with $coupon_codes=array();







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 13 '18 at 3:53









                          Vaibhav Kumar GoyalVaibhav Kumar Goyal

                          674613




                          674613






























                              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%2f47322228%2fadd-applied-coupon-code-in-admin-new-order-email-template-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.

                              Danny Elfman

                              Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues