1010use WP_Express_Checkout \Products ;
1111use WP_Express_Checkout \Utils ;
1212use WP_Express_Checkout \Variations ;
13+ use WP_Express_Checkout \Debug \Logger ;
1314use WP_Post ;
1415
1516/**
@@ -36,6 +37,7 @@ public function __construct() {
3637 add_action ( 'wp_ajax_wpec_add_order_note ' , array ( $ this , 'wpec_add_order_note_callback ' ) );
3738 add_action ( 'wp_ajax_wpec_delete_order_note ' , array ( $ this , 'wpec_delete_order_note_callback ' ) );
3839 add_action ( 'wp_ajax_wpec_get_order_product_by_id ' , array ( $ this , 'wpec_get_order_product_by_id_callback ' ) );
40+ add_action ( 'wp_ajax_wpec_order_action_set_paid_and_send_email ' , array ( $ this , 'set_paid_and_send_email_callback ' ) );
3941 }
4042
4143 public function add_meta_boxes () {
@@ -354,7 +356,7 @@ public function display_actions_meta_box( $post ){
354356
355357 try {
356358 $ order = Orders::retrieve ( $ post ->ID );
357- $ is_manual_payment = strpos ($ order ->get_capture_id (), 'manual ' );
359+ $ is_manual_payment = strtolower ($ order ->get_payment_gateway ()) == ' manual_checkout ' || stripos ( $ order -> get_capture_id (), 'manual ' ) !== false ;
358360 $ is_admin_checkout = strpos ($ order ->get_capture_id (), 'admin ' );
359361 } catch ( Exception $ exc ) {
360362 return ;
@@ -377,7 +379,7 @@ public function display_actions_meta_box( $post ){
377379 </span>
378380 </a>
379381 </li>
380- <?php if ($ is_manual_payment === false && $ is_admin_checkout === false ) { // Don't show refund action button for manual payment or admin checkout ?>
382+ <?php if ( empty ( $ is_manual_payment) && $ is_admin_checkout === false ) { // Don't show refund action button for manual payment or admin checkout ?>
381383 <li>
382384 <?php if ( $ order ->get_status ()=="refunded " ){ ?>
383385 <div class="wpec-grey-box">
@@ -395,6 +397,17 @@ public function display_actions_meta_box( $post ){
395397 <?php } ?>
396398 </li>
397399 <?php } ?>
400+
401+ <?php if ( !empty ($ is_manual_payment ) && strtolower ($ order ->get_status ()) == 'pending ' ) { ?>
402+ <li>
403+ <a class="button wpec-order-action" data-action="set_paid_and_send_email" data-order="<?php echo $ order ->get_id () ?> " data-nonce="<?php echo wp_create_nonce ( 'set_paid_and_send_email ' ); ?> " href="#">
404+ <span class="dashicons dashicons-yes-alt" style="line-height:1.8;font-size:16px;"></span>
405+ <span class="wpec-order-action-label">
406+ <?php esc_html_e ( 'Set Order Paid & Send Email ' , 'wp-express-checkout ' ); ?>
407+ </span>
408+ </a>
409+ </li>
410+ <?php } ?>
398411 </ul>
399412 <?php
400413
@@ -651,6 +664,29 @@ public function payment_refund_callback()
651664 wp_send_json_success ( __ ( 'Order refunded successfully! ' , 'wp-express-checkout ' ) );
652665 }
653666
667+ public function set_paid_and_send_email_callback (){
668+
669+ check_ajax_referer ( 'set_paid_and_send_email ' , 'nonce ' );
670+
671+ try {
672+ $ order = Orders::retrieve ( $ _POST ['order ' ] );
673+
674+ } catch ( Exception $ exc ) {
675+ wp_send_json_error ( $ exc ->getMessage () );
676+ }
677+
678+ Logger::log ( "Setting order status to 'paid'. " );
679+ $ order ->set_status ('paid ' );
680+
681+ $ response = Emails::send_buyer_email ( $ order );
682+
683+ if ( ! $ response ) {
684+ wp_send_json_error ( __ ( 'Something went wrong, email is not sent! ' , 'wp-express-checkout ' ) );
685+ }
686+
687+ wp_send_json_success ( __ ( 'Order has set to paid and buyer notification email sent successfully! ' , 'wp-express-checkout ' ) );
688+ }
689+
654690 public function wpec_add_order_note_callback ()
655691 {
656692 check_ajax_referer ( 'wpec_add_order_note_ajax_nonce ' , 'nonce ' );
0 commit comments