Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_thankyou', 'bdev_email_subject_and_message_based_on_payment_gatway', 10, 1 );
- function bdev_email_subject_and_message_based_on_payment_gatway( $order_id ) {
- if ( ! $order_id ) return;
- // get the order details
- $order = wc_get_order( $order_id );
- // get the customer information by getting their name and email using billing_XX_name and billing_email
- $customer_complete_name_and_email = $order->billing_first_name . ' ' . $order->billing_last_name . ' <' . $order->billing_email . '>';
- // shop owner and/ or shop details
- $headers = 'From: Shop Name <name@example.com>' . "\r\n";
- // cod = cash on delivery
- if ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) {
- $subject = 'your subject';
- $message = 'your custom message here';
- }
- // cheque = check payment
- elseif ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) {
- $subject = 'your subject';
- $message = 'your custom message here';
- }
- // your standard payment option
- else {
- $subject = 'your subject';
- $message = 'your custom message here';
- }
- if( $subject & $message) {
- wp_mail($customer_complete_name_and_email, $subject, $message, $headers );
- }
- }
- // BONUS
- // This is how you can find out all your active payment gateways and their slug
- // looking at line 15, cod is the slug of cash on delivery
- // run this code once, write down your slugs and then remove it
- // the slugs will be shown on the shop page
- function bdev_your_active_payment_gateways() {
- if ( is_user_logged_in() ) {
- $current_user = wp_get_current_user();
- if (user_can( $current_user, 'administrator' )) {
- 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>';
- foreach(WC()->payment_gateways->get_available_payment_gateways() as $payment_gateway)
- echo '<div><b>Gateway Name:</b> '.$payment_gateway->title .' <br> <b>'.$payment_gateway->title .' Slug:</b> '.$payment_gateway->id .'<br><br></div>';
- }
- }
- }
- add_action( 'woocommerce_before_main_content', 'bdev_your_active_payment_gateways', 1 );
Add Comment
Please, Sign In to add comment