add_payment_method_to_new_order

The WooCommerce Checkout Manager add payment method to new order function.

Description

add_payment_method_to_new_order( $order, $sent_to_admin, $plain_text ); 

Parameters (3)

0. $order
The order.
1. $sent_to_admin
The sent to admin.
2. $plain_text
The plain text.

Usage

  1. if ( !function_exists( 'add_payment_method_to_new_order' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/main.php'; 
  3.  
  4. // The order. 
  5. $order = null; 
  6.  
  7. // The sent to admin. 
  8. $sent_to_admin = null; 
  9.  
  10. // The plain text. 
  11. $plain_text = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = add_payment_method_to_new_order($order, $sent_to_admin, $plain_text); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/classes/main.php  
  1. function add_payment_method_to_new_order( $order, $sent_to_admin, $plain_text ) { 
  2.  
  3. $shipping = array( 'country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode' ); 
  4. $billing = array( 'country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode', 'email', 'phone' ); 
  5.  
  6. $names = array( 'billing', 'shipping' ); 
  7. $inc = 3; 
  8.  
  9. if( $plain_text ) { 
  10.  
  11. foreach( $names as $name ) { 
  12.  
  13. $array = ($name == 'billing') ? $billing : $shipping; 
  14.  
  15. $options = get_option( 'wccs_settings'.$inc.'' ); 
  16.  
  17. foreach ( $options[''.$name.'_buttons'] as $btn ) : 
  18.  
  19.  
  20. if ( !in_array( $btn['cow'], $array ) ) { 
  21. if ( (''.get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] !== 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  22. echo ''.wpml_string_wccm_pro($btn['label']).': '.nl2br(get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)).''; 
  23. echo "\n"; 
  24.  
  25. } elseif ( !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] == 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  26. echo '' .wpml_string_wccm_pro($btn['label']). ''; 
  27. echo "\n"; 
  28.  
  29. } elseif ( (''.get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] !== 'heading') && $btn['type'] !== 'wooccmupload' && (($btn['type'] == 'multiselect') || ($btn['type'] == 'multicheckbox')) ) { 
  30. $strings = unserialize(get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)); 
  31. $iww = 0; 
  32. $len = count($strings); 
  33.  
  34. echo ''.wpml_string_wccm_pro($btn['label']).': '; 
  35. foreach($strings as $key ) { 
  36. if ($iww == $len - 1) { 
  37. echo ''.$key.''; 
  38. } else { 
  39. echo ''.$key.', '; 
  40. $iww++; 
  41. echo "\n"; 
  42. }elseif( $btn['type'] == 'wooccmupload' ) { 
  43. $info = explode( "||", get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)); 
  44. echo ''.wpml_string_wccm_pro($btn['force_title2']).': '.$info[0].''; 
  45. echo "\n"; 
  46. endforeach; 
  47. $inc--; 
  48.  
  49. $options = get_option( 'wccs_settings' ); 
  50.  
  51. foreach ( $options['buttons'] as $btn ) : 
  52.  
  53. if ( (''.get_post_meta( $order->id , ''.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] !== 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  54. echo ''.wpml_string_wccm_pro($btn['label']).': '.nl2br(get_post_meta( $order->id , ''.$btn['cow'].'', true)).''; 
  55. echo "\n"; 
  56.  
  57. } elseif ( !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] == 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  58. echo ''.wpml_string_wccm_pro($btn['label']).''; 
  59. echo "\n"; 
  60.  
  61. } elseif ( (''.get_post_meta( $order->id , ''.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] !== 'heading') && $btn['type'] !== 'wooccmupload' && (($btn['type'] == 'multiselect') || ($btn['type'] == 'multicheckbox')) ) { 
  62.  
  63. $strings = unserialize(get_post_meta( $order->id , ''.$btn['cow'].'', true)); 
  64. $iww = 0; 
  65. $len = count($strings); 
  66.  
  67. echo ''.wpml_string_wccm_pro($btn['label']).': '; 
  68. foreach($strings as $key ) { 
  69. if ($iww == $len - 1) { 
  70. echo ''.$key.''; 
  71. } else { 
  72. echo ''.$key.', '; 
  73. $iww++; 
  74. echo "\n"; 
  75. }elseif( $btn['type'] == 'wooccmupload' ) { 
  76. $info = explode("||", get_post_meta( $order->id , ''.$btn['cow'].'', true)); 
  77. echo ''.wpml_string_wccm_pro($btn['force_title2']).': '.$info[0].''; 
  78. echo "\n"; 
  79. endforeach; 
  80.  
  81.  
  82. if ( !empty($options['checkness']['set_timezone']) ) { 
  83. date_default_timezone_set(''.$options['checkness']['set_timezone'].''); 
  84. $date = ( !empty($options['checkness']['twenty_hour'])) ? date("G:i T (P").' GMT)' : date("g:i a"); 
  85. if ( $options['checkness']['time_stamp'] == true ) { 
  86. echo ''.$options['checkness']['time_stamp_title'].' ' . $date . "\n"; 
  87. if ( $order->payment_method_title && $options['checkness']['payment_method_t'] == true ) { 
  88. echo ''.$options['checkness']['payment_method_d'].': ' . $order->payment_method_title . "\n"; 
  89. if ( $order->shipping_method_title && ($options['checkness']['shipping_method_t'] == true)) { 
  90. echo ''.$options['checkness']['shipping_method_d'].': ' . $order->shipping_method_title . "\n"; 
  91.  
  92. echo "\n"; 
  93. } else { 
  94. foreach( $names as $name ) { 
  95.  
  96. $array = ($name == 'billing') ? $billing : $shipping; 
  97.  
  98. $options = get_option( 'wccs_settings'.$inc.'' ); 
  99.  
  100. foreach ( $options[''.$name.'_buttons'] as $btn ) : 
  101.  
  102.  
  103. if ( !in_array( $btn['cow'], $array ) ) { 
  104. if ( (''.get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] !== 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  105. echo '<p><strong>'.wpml_string_wccm_pro($btn['label']).':</strong> '.nl2br(get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)).'</p>'; 
  106.  
  107. } elseif ( !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] == 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  108. echo '<h2>' .wpml_string_wccm_pro($btn['label']). '</h2>'; 
  109.  
  110. } elseif ( (''.get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty( $btn['deny_receipt'] ) && ($btn['type'] !== 'heading') && $btn['type'] !== 'wooccmupload' && (($btn['type'] == 'multiselect') || ($btn['type'] == 'multicheckbox')) ) { 
  111. $strings = unserialize(get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)); 
  112. $iww = 0; 
  113. $len = count($strings); 
  114.  
  115. echo '<p><strong>'.wpml_string_wccm_pro($btn['label']).':</strong> '; 
  116. foreach($strings as $key ) { 
  117. if ($iww == $len - 1) { 
  118. echo ''.$key.''; 
  119. } else { 
  120. echo ''.$key.', '; 
  121. $iww++; 
  122. echo '</p>'; 
  123. }elseif( $btn['type'] == 'wooccmupload' ) { 
  124. $info = explode("||", get_post_meta( $order->id , '_'.$name.'_'.$btn['cow'].'', true)); 
  125. echo '<p><strong>'.wpml_string_wccm_pro($btn['force_title2']).':</strong> '.$info[0].'</p>'; 
  126. endforeach; 
  127. $inc--; 
  128.  
  129. $options = get_option( 'wccs_settings' ); 
  130.  
  131. foreach ( $options['buttons'] as $btn ) : 
  132.  
  133. if ( (''.get_post_meta( $order->id , ''.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] !== 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  134. echo '<p><strong>'.wpml_string_wccm_pro($btn['label']).':</strong> '.nl2br(get_post_meta( $order->id , ''.$btn['cow'].'', true)).'</p>'; 
  135.  
  136. } elseif ( !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] == 'heading') && ($btn['type'] !== 'multiselect') && $btn['type'] !== 'wooccmupload' && ($btn['type'] !== 'multicheckbox') ) { 
  137. echo '<h2>'.wpml_string_wccm_pro($btn['label']).'</h2>'; 
  138.  
  139. } elseif ( (''.get_post_meta( $order->id , ''.$btn['cow'].'', true).'' !== '') && !empty( $btn['label'] ) && empty($btn['deny_receipt']) && ($btn['type'] !== 'heading') && $btn['type'] !== 'wooccmupload' && (($btn['type'] == 'multiselect') || ($btn['type'] == 'multicheckbox')) ) { 
  140.  
  141. $strings = unserialize(get_post_meta( $order->id , ''.$btn['cow'].'', true)); 
  142. $iww = 0; 
  143. $len = count($strings); 
  144.  
  145. echo '<p><strong>'.wpml_string_wccm_pro($btn['label']).':</strong> '; 
  146. foreach($strings as $key ) { 
  147. if ($iww == $len - 1) { 
  148. echo ''.$key.''; 
  149. } else { 
  150. echo ''.$key.', '; 
  151. $iww++; 
  152. echo '</p>'; 
  153. }elseif( $btn['type'] == 'wooccmupload' ) { 
  154. $info = explode( "||", get_post_meta( $order->id , ''.$btn['cow'].'', true)); 
  155. echo '<p><strong>'.wpml_string_wccm_pro($btn['force_title2']).':</strong> '.$info[0].'</p>'; 
  156. endforeach; 
  157.  
  158.  
  159. if ( !empty($options['checkness']['set_timezone']) ) { 
  160. date_default_timezone_set(''.$options['checkness']['set_timezone'].''); 
  161. $date = ( !empty($options['checkness']['twenty_hour'])) ? date("G:i T (P").' GMT)' : date("g:i a"); 
  162. if ( $options['checkness']['time_stamp'] == true ) { 
  163. echo '<p><strong>'.$options['checkness']['time_stamp_title'].':</strong> ' . $date . '</p>'; 
  164. if ( $order->payment_method_title && $options['checkness']['payment_method_t'] == true ) { 
  165. echo '<p><strong>'.$options['checkness']['payment_method_d'].':</strong> ' . $order->payment_method_title . '</p>'; 
  166. if ( $order->shipping_method_title && ($options['checkness']['shipping_method_t'] == true)) { 
  167. echo '<p><strong>'.$options['checkness']['shipping_method_d'].':</strong> ' . $order->shipping_method_title . '</p>'; 
  168.  
  169.