Advertisement
palsushobhan

wcfm_registration_details_admin_email

Aug 15th, 2022
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.66 KB | None | 0 0
  1. /* Add support for a email placeholder {vendor_data} in New vendor notification email to the admin */
  2. class WCFM_Vendor_Registration_Application_Data {
  3.     private $vendor_id = null;
  4.     public function __construct($member_id) {
  5.         $this->vendor_id = $member_id;
  6.         add_filter('wcfm_email_content_wrapper', array(&$this, 'add_new_email_placeholder_support'), 10, 2);
  7.     }
  8.     public function add_new_email_placeholder_support($message, $email_type) {
  9.         if($this->vendor_id && $email_type == __( 'New Vendor', 'wc-multivendor-membership' )) {
  10.             $member_data = get_userdata( $this->vendor_id );
  11.             $store_name = get_user_meta( $this->vendor_id, 'store_name', true );
  12.             $paymode = get_user_meta( $this->vendor_id, 'wcfm_membership_paymode', true );
  13.             if( $paymode ) {
  14.                 $wcfm_membership_payment_methods = get_wcfm_membership_payment_methods();
  15.                 if( in_array( $paymode, array( 'paypal_subs', 'paypal_subs_subs' ) ) ) $paymode = 'paypal';
  16.                 if( in_array( $paymode, array( 'stripe', 'stripe_subs', 'stripe_subs_subs' ) ) ) $paymode = 'stripe';
  17.                 if( in_array( $paymode, array( 'bank_transfer', 'bank_transfer_subs' ) ) ) $paymode = 'bank_transfer';
  18.                 if( !$paymode ) $paymode = 'bank_transfer';
  19.                 if( isset( $wcfm_membership_payment_methods[$paymode] ) ) {
  20.                     $paymode = $wcfm_membership_payment_methods[$paymode];
  21.                 } else {
  22.                     if ( WC()->payment_gateways() ) {
  23.                         $payment_gateways = WC()->payment_gateways->payment_gateways();
  24.                         $paymode = isset( $payment_gateways[ $paymode ] ) ? esc_html( $payment_gateways[ $paymode ]->get_title() ) : __( 'FREE', 'wc-multivendor-membership' );
  25.                     }
  26.                 }
  27.             }
  28.             $wcfmvm_registration_static_fields = wcfm_get_option( 'wcfmvm_registration_static_fields', array() );
  29.             $wcfmvm_static_infos = (array) get_user_meta( $this->vendor_id, 'wcfmvm_static_infos', true ); 
  30.             $wcfmvm_registration_custom_fields = wcfm_get_option( 'wcfmvm_registration_custom_fields', array() );
  31.             $wcfmvm_custom_infos = (array) get_user_meta( $this->vendor_id, 'wcfmvm_custom_infos', true );
  32.  
  33.             $store_data_html = '<h2>' . __( 'Application Details', 'wc-multivendor-membership' ) . '</h2>';
  34.             $store_data_html .= '<table width="100%" style="width:100%;">';
  35.             if( isset( $wcfmvm_registration_static_fields['first_name'] ) ) {
  36.                 $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'First Name', 'wc-multivendor-membership' ) . '</td>';
  37.                 $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . esc_html($member_data->first_name) . '</td></tr>';
  38.             }
  39.             if( isset( $wcfmvm_registration_static_fields['last_name'] ) ) {
  40.                 $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'Last Name', 'wc-multivendor-membership' ) . '</td>';
  41.                 $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . esc_html($member_data->last_name) . '</td></tr>';
  42.             }
  43.             $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'User Name', 'wc-multivendor-membership' ) . '</td>';
  44.             $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . esc_html($member_data->user_login) . '</td></tr>';
  45.             $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'Email', 'wc-multivendor-membership' ) . '</td>';
  46.             $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . esc_html($member_data->user_email) . '</td></tr>';
  47.             $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'Email', 'wc-multivendor-membership' ) . '</td>';
  48.             $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . $store_name . '</td></tr>';
  49.             if( isset( $paymode ) ) {
  50.                 $store_data_html .= '<tr><td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;">' . esc_html( 'Pay mode', 'wc-multivendor-membership' ) . '</td>';
  51.                 $store_data_html .= '<td colspan="5" style="background-color: #f8f8f8;padding: 1em;">' . wp_kses_post($paymode) . '</td></tr>';
  52.             }
  53.             ob_start();
  54.             if( !empty( $wcfmvm_registration_static_fields ) ) {
  55.                 foreach( $wcfmvm_registration_static_fields as $wcfmvm_registration_static_field => $wcfmvm_registration_static_field_val ) {
  56.                     $field_value = array();
  57.                     $field_name = 'wcfmvm_static_infos[' . $wcfmvm_registration_static_field . ']';
  58.                    
  59.                     if( !empty( $wcfmvm_static_infos ) ) {
  60.                         $field_value = isset( $wcfmvm_static_infos[$wcfmvm_registration_static_field] ) ? $wcfmvm_static_infos[$wcfmvm_registration_static_field] : array();
  61.                     }
  62.                    
  63.                     switch( $wcfmvm_registration_static_field ) {
  64.                         case 'address':
  65.                             if( isset($field_value['addr_1']) ) {
  66.                                 $state_code = $field_value['state'];
  67.                                 $country_code = $field_value['country'];
  68.                                 $state   = isset( WC()->countries->states[ $country_code ][ $state_code ] ) ? WC()->countries->states[ $country_code ][ $state_code ] : $state_code;
  69.                                 $country = isset( WC()->countries->countries[ $country_code ] ) ? WC()->countries->countries[ $country_code ] : $country_code;
  70.                                
  71.                                 $address = $field_value['addr_1'] . ' ' . $field_value['addr_2']. '<br/>' . $field_value['city']. ', ' . $state. '<br />' . $field_value['zip']. '<br />' . $country;
  72.                                 ?>
  73.                                 <tr>
  74.                                     <td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php esc_html_e( 'Store Address', 'wc-frontend-manager' ); ?></td>
  75.                                     <td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo wp_kses_post($address); ?></td>
  76.                                 </tr>
  77.                                 <?php
  78.                             }
  79.                         break;
  80.                        
  81.                         case 'phone':
  82.                             ?>
  83.                             <tr>
  84.                                 <td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php esc_html_e( 'Store Phone', 'wc-frontend-manager' ); ?></td>
  85.                                 <td colspan="5" style="background-color: #f8f8f8;padding: 1em;"><?php echo wp_kses_post($field_value); ?></td>
  86.                             </tr>
  87.                             <?php
  88.                         break;
  89.                        
  90.                         default:
  91.                             do_action( 'wcfmvm_registration_static_field_popup_show', $this->vendor_id, $wcfmvm_registration_static_field, $field_value );
  92.                         break;
  93.                     }
  94.                 }
  95.             }
  96.  
  97.             if( !empty( $wcfmvm_registration_custom_fields ) ) {
  98.                 foreach( $wcfmvm_registration_custom_fields as $wcfmvm_registration_custom_field ) {
  99.                     if( !isset( $wcfmvm_registration_custom_field['enable'] ) ) continue;
  100.                     if( !$wcfmvm_registration_custom_field['label'] ) continue;
  101.                     $field_value = '';
  102.                     $wcfmvm_registration_custom_field['name'] = sanitize_title( $wcfmvm_registration_custom_field['label'] );
  103.                
  104.                     if( !empty( $wcfmvm_custom_infos ) ) {
  105.                         if( $wcfmvm_registration_custom_field['type'] == 'checkbox' ) {
  106.                             $field_value = isset( $wcfmvm_custom_infos[$wcfmvm_registration_custom_field['name']] ) ? $wcfmvm_custom_infos[$wcfmvm_registration_custom_field['name']] : 'no';
  107.                         } elseif( $wcfmvm_registration_custom_field['type'] == 'upload' ) {
  108.                             $field_name  = 'wcfmvm_custom_infos[' . $wcfmvm_registration_custom_field['name'] . ']';
  109.                             $field_id    = md5( $field_name );
  110.                             $field_value = isset( $wcfmvm_custom_infos[$field_id] ) ? $wcfmvm_custom_infos[$field_id] : '';
  111.                         } else {
  112.                             $field_value = isset( $wcfmvm_custom_infos[$wcfmvm_registration_custom_field['name']] ) ? $wcfmvm_custom_infos[$wcfmvm_registration_custom_field['name']] : '';
  113.                         }
  114.                     }
  115.                     ?>
  116.                     <tr>
  117.                         <td colspan="3" style="background-color: #eeeeee;padding: 1em 1.41575em;line-height: 1.5;"><?php esc_html_e( $wcfmvm_registration_custom_field['label'], 'WCfM'); ?></td>
  118.                         <td colspan="5" style="background-color: #f8f8f8;padding: 1em;">
  119.                             <?php
  120.                             if( $field_value && $wcfmvm_registration_custom_field['type'] == 'upload' ) {
  121.                                 echo '<a class="wcfm-wp-fields-uploader" target="_blank" style="width: 32px; height: 32px;" href="' . esc_url(wcfm_get_attachment_url( $field_value )) . '">Upload</a>';
  122.                             } else {
  123.                                 if( !$field_value ) $field_value = '&ndash;';
  124.                                 if( is_array( $field_value ) ) echo wp_kses_post(implode( ', ', $field_value ));
  125.                                 else echo wp_kses_post($field_value);
  126.                             }
  127.                             ?>
  128.                         </td>
  129.                     </tr>
  130.                     <?php
  131.                 }
  132.             }
  133.  
  134.             $store_data_html .= ob_get_clean();
  135.             $store_data_html .= '</table><br />';
  136.             $message = str_replace( '{vendor_data}', $store_data_html, $message );
  137.         }
  138.         return $message;
  139.     }
  140. }
  141. add_action( 'wcfmmp_new_store_created', function($store_id) {
  142.     new WCFM_Vendor_Registration_Application_Data($store_id);
  143. }, 12 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement