Guest User

Untitled

a guest
Jan 19th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. add_action( 'woocommerce_thankyou', 'bdev_email_subject_and_message_based_on_payment_gatway', 10, 1 );
  2. function bdev_email_subject_and_message_based_on_payment_gatway( $order_id ) {
  3. if ( ! $order_id ) return;
  4.  
  5. // get the order details
  6. $order = wc_get_order( $order_id );
  7.  
  8. // get the customer information by getting their name and email using billing_XX_name and billing_email
  9. $customer_complete_name_and_email = $order->billing_first_name . ' ' . $order->billing_last_name . ' <' . $order->billing_email . '>';
  10.  
  11. // shop owner and/ or shop details
  12. $headers = 'From: Shop Name <name@example.com>' . "\r\n";
  13.  
  14. // cod = cash on delivery
  15. if ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) {
  16. $subject = 'your subject';
  17. $message = 'your custom message here';
  18. }
  19.  
  20. // cheque = check payment
  21. elseif ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) {
  22. $subject = 'your subject';
  23. $message = 'your custom message here';
  24. }
  25.  
  26. // your standard payment option
  27. else {
  28. $subject = 'your subject';
  29. $message = 'your custom message here';
  30. }
  31. if( $subject & $message) {
  32. wp_mail($customer_complete_name_and_email, $subject, $message, $headers );
  33. }
  34. }
  35.  
  36.  
  37. // BONUS
  38. // This is how you can find out all your active payment gateways and their slug
  39. // looking at line 15, cod is the slug of cash on delivery
  40. // run this code once, write down your slugs and then remove it
  41. // the slugs will be shown on the shop page
  42. function bdev_your_active_payment_gateways() {
  43. if ( is_user_logged_in() ) {
  44. $current_user = wp_get_current_user();
  45. if (user_can( $current_user, 'administrator' )) {
  46. echo '<span style="font-size: 25px; color: white; display: block; background-color: red; text-align: center; border-radius: 30px;">These are the activated payment gateways on your website</span><br><br>';
  47. foreach(WC()->payment_gateways->get_available_payment_gateways() as $payment_gateway)
  48. echo '<div><b>Gateway Name:</b> '.$payment_gateway->title .' <br> <b>'.$payment_gateway->title .' Slug:</b> '.$payment_gateway->id .'<br><br></div>';
  49. }
  50. }
  51. }
  52. add_action( 'woocommerce_before_main_content', 'bdev_your_active_payment_gateways', 1 );
Add Comment
Please, Sign In to add comment