WPPizza – A Restaurant Plugin for WordPress › Support › General Support › Need to add the Payment type in email Subject Line
- AuthorPosts
- 30 July, 2018 at 11:48 pm #38629
Hi Olly,
please tell me how can i add the payment type in the subject line of the order emails. (V3.X)
Thx
31 July, 2018 at 1:26 pm #38631as 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
31 July, 2018 at 6:32 pm #38632Pate the code in the file class.wppizza.order_execute.php ?
31 July, 2018 at 6:34 pm #38633NO
you MUST learn about wordpress filters and actions and how they work
https://docs.wp-pizza.com/developers/?section=filters-actions-functions31 July, 2018 at 6:37 pm #38634PS: never EVER edit core files (of ANY plugin, theme or indeed core wordpress files)
(with – very very – few exceptions that is.)31 July, 2018 at 6:44 pm #38635in 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
1 August, 2018 at 12:42 am #38640Ok 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
1 August, 2018 at 1:41 am #38642apologies, 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;
1 August, 2018 at 11:25 pm #38658Thx Olly! It works!
- AuthorPosts
- The topic ‘Need to add the Payment type in email Subject Line’ is closed to new replies.