Need to add the Payment type in email Subject Line

WPPizza – A Restaurant Plugin for WordPress Support General Support Need to add the Payment type in email Subject Line

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #38629
    Lutz Debus
    Participant

      Hi Olly,

      please tell me how can i add the payment type in the subject line of the order emails. (V3.X)

      Thx

      #38631
      Olly
      Admin & Mod

        as of WPPizza v3.6.6 – and earlier – you can do this

        
        add_filter('wppizza_filter_email_subject', 'prefix_filter_email_subject', 10 , 2);
        function prefix_filter_email_subject($subject, $order){
        /* 
        $subject is an array made up of 
        $subject['prefix'] - typically contains blogname followed by items added to subject line in wppizza->order form 
        $subject['main'] - typically contains "your order" localization string (wppizza->localization)
        $subject['suffix'] - typically contains date of order according to date/time format set in WP->settings
        */
        /* example: adding the "initiator" (i.e payment gateway ident) after the prefix - typically "COD" or "STRIPE" etc, tweak as required, perhaps use some conditionals to change the label to something else if "COD" etc etc */
        $subject['prefix'] .= ' '.$order -> initiator;
        return $subject;
        }
        

        the next / later version will have an additional parameter in the filter that has the order details already formatted

        
        add_filter('wppizza_filter_email_subject', 'prefix_filter_email_subject', 10 , 3);
        function prefix_filter_email_subject($subject, $order, $order_formatted){
        /* 
        $subject is an array made up of 
        $subject['prefix'] - typically contains blogname followed by items added to subject line in wppizza->order form 
        $subject['main'] - typically contains "your order" localization string (wppizza->localization)
        $subject['suffix'] - typically contains date of order according to date/time format set in WP->settings
        */
        /* example: adding the label of a gateway as set in wppizza->gateways after the prefix , tweak as required*/	
        $subject['prefix'] .= ' '.$order_formatted['ordervars']['payment_type']['value_formatted'];
        /* example2: adding the paymet method (i.e typically simply  "Cash" or "Credit Card" ) , tweak as required*/	
        $subject['prefix'] .= ' '.$order_formatted['ordervars']['payment_method']['value_formatted'];
        /* see $order_formatted for all available parameters */
        return $subject;
        }
        

        in both cases the $subject array returned will be imploded with a space between each key

        #38632
        Lutz Debus
        Participant

          Pate the code in the file class.wppizza.order_execute.php ?

          #38633
          Olly
          Admin & Mod

            NO
            you MUST learn about wordpress filters and actions and how they work
            https://docs.wp-pizza.com/developers/?section=filters-actions-functions

            #38634
            Olly
            Admin & Mod

              PS: never EVER edit core files (of ANY plugin, theme or indeed core wordpress files)
              (with – very very – few exceptions that is.)

              #38635
              Olly
              Admin & Mod

                in fact (and then I promise I’ll shut up 🙂 ) actions/filter hooks exist precisely for the reason that you do not have to touch core files but can extend/change a/some functionality of a plugin/theme/wordpress

                #38640
                Lutz Debus
                Participant

                  Ok i understand and put it into my child theme functions.php
                  But the order will not be executed:

                  logfile:

                  PHP Fatal error: Cannot use object of type stdClass as array in /var/www/www.domain.comde/html/subdir/wp-content/themes/albinomouse-pup/functions.php on line 17

                  #38642
                  Olly
                  Admin & Mod

                    apologies, my fault i think (i didnt test this and only did it from memory)

                    i believe the

                    
                    $subject['prefix'] .= ' '.$order['initiator'];
                    

                    in the first example (now corrected) should actually be

                    
                    $subject['prefix'] .= ' '.$order->initiator;
                    
                    #38658
                    Lutz Debus
                    Participant

                      Thx Olly! It works!

                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • The topic ‘Need to add the Payment type in email Subject Line’ is closed to new replies.