function wc_crm_actions_customer_detail() { if (isset($_GET['page']) && $_GET['page'] != 'wc_new_customer') { return; } $wc_crm_customer_details = new WC_Crm_Customer_Details(0, 0); if (isset($_POST['wc_crm_customer_action'])) { if (isset($_POST['customer_user']) && !empty($_POST['customer_user'])) { $wc_crm_customer_details->save($_POST['customer_user']); } if (isset($_POST['order_id']) && !empty($_POST['order_id'])) { $wc_crm_customer_details->save($_POST['order_id'], false, true); } else { $wc_crm_customer_details->create_user(); } } }
/** * Handle CSV file download */ function export_csv() { header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename=customers_' . date('Y-m-d') . '.csv'); header('Pragma: no-cache'); $__wc_crm_customer_details = new WC_Crm_Customer_Details(0, 0); $__wc_crm_customer_details->init_address_fields('', '', false); $__b_address = $__wc_crm_customer_details->billing_fields; $__s_address = $__wc_crm_customer_details->shipping_fields; $o = WC_CRM()->orders(); $data = $o->get_orders(); echo '"Customer name",'; foreach ($__b_address as $key => $label) { if ($key == 'first_name' || $key == 'last_name') { continue; } echo '"Billing ' . $label['label'] . '",'; } foreach ($__s_address as $key => $label) { if ($key == 'first_name' || $key == 'last_name') { continue; } echo '"Shipping ' . $label['label'] . '",'; } echo '"Username",'; echo '"Last purchase date",'; echo '"Number of orders",'; echo '"Total value",'; echo "\"Subscribed\"\n"; if (woocommerce_crm_mailchimp_enabled()) { $members = woocommerce_crm_get_members(); } foreach ($data as $item) { //$item = get_object_vars ( $customer ); if ($item['user_id']) { $user_id = $item['user_id']; $wc_crm_customer_details = new WC_Crm_Customer_Details($user_id, 0); $wc_crm_customer_details->init_address_fields('', '', false); $b_address = $wc_crm_customer_details->billing_fields; $s_address = $wc_crm_customer_details->shipping_fields; $data = get_user_meta($item['user_id']); echo '"' . $data['first_name'][0] . ' ' . $data['last_name'][0] . '",'; foreach ($b_address as $key => $value) { if ($key == 'first_name' || $key == 'last_name') { continue; } if ($key == 'country') { echo '"' . $item['country'] . '",'; continue; } if ($key == 'email') { echo '"' . $item['email'] . '",'; continue; } $field_name = 'billing_' . $key; $field_value = get_user_meta($user_id, $field_name, true); echo '"' . $field_value . '",'; } foreach ($s_address as $key => $value) { if ($key == 'first_name' || $key == 'last_name') { continue; } $field_name = 'shipping_' . $key; $field_value = get_user_meta($user_id, $field_name, true); echo '"' . $field_value . '",'; } $user = @get_userdata($user_id); echo '"' . (isset($user->user_login) ? $user->user_login : __('Guest', 'wc_customer_relationship_manager')) . '",'; $item['num_orders'] = wc_crm_get_num_orders($item['user_id']); $item['total_spent'] = wc_crm_get_order_value($item['user_id']); } else { $order_id = $item['order_id']; $user_id = 0; $order = new WC_Order($order_id); $wc_crm_customer_details_g = new WC_Crm_Customer_Details(0, $order_id); $wc_crm_customer_details_g->init_address_fields('', '', false); $b_address = $wc_crm_customer_details_g->billing_fields; $s_address = $wc_crm_customer_details_g->shipping_fields; $first_name = get_post_meta($item['order_id'], '_billing_first_name', true); $last_name = get_post_meta($item['order_id'], '_billing_last_name', true); echo '"' . $first_name . ' ' . $last_name . '",'; foreach ($b_address as $key => $value) { if ($key == 'first_name' || $key == 'last_name') { continue; } if ($key == 'country') { echo '"' . $item['country'] . '",'; continue; } if ($key == 'email') { echo '"' . $item['email'] . '",'; continue; } $name_var = 'billing_' . $key; $field_value = $wc_crm_customer_details_g->order->{$name_var}; echo '"' . $field_value . '",'; } foreach ($s_address as $key => $value) { if ($key == 'first_name' || $key == 'last_name') { continue; } $var_name = 'shipping_' . $key; $field_value = $wc_crm_customer_details_g->order->{$name_var}; echo '"' . $field_value . '",'; } echo '"' . __('Guest', 'wc_customer_relationship_manager') . '",'; $item['num_orders'] = wc_crm_get_num_orders($item['email'], '_billing_email', true); $item['total_spent'] = wc_crm_get_order_value($item['email'], '_billing_email', true); } $total_spent = wc_crm_price_num_decimals($item['total_spent']); $last_purchase = $item['order_id'] ? woocommerce_crm_get_pretty_time($item['order_id'], true) : ''; echo '"' . $last_purchase . '",'; echo '"' . $item['num_orders'] . '",'; if (woocommerce_crm_mailchimp_enabled()) { $enrolled_plain = in_array($item['email'], $members) ? 'yes' : 'no'; echo '"' . $total_spent . '",'; echo '"' . $enrolled_plain . "\"\n"; } else { echo '"' . $total_spent . "\"\n"; } } }
function column_customer_notes($item) { if ($item['user_id'] && !empty($item['user_id']) && get_userdata($item['user_id'])) { $wc_crm_customer_details = new WC_Crm_Customer_Details($item['user_id']); $notes = $wc_crm_customer_details->get_last_customer_note(); if ($notes == 'No Customer Notes') { $customer_notes = '<span class="note-off">-</span>'; } else { $customer_notes = '<a href="admin.php?page=wc_new_customer&screen=customer_notes&user_id=' . $item['user_id'] . '" class="open_c_notes note-on tips" data-tip="' . $notes . '"></a>'; } return $customer_notes; } else { if ($item['order_id'] && !empty($item['order_id'])) { return '<span class="note-off">-</span>'; } } }
public function select_customer_id() { if (isset($_GET['post_type']) && $_GET['post_type'] == 'shop_order' && isset($_GET['user_id']) && !empty($_GET['user_id'])) { $user_id = $_GET['user_id']; ob_start(); $c_name = get_user_meta($user_id, 'user_firstname', true) . ' ' . get_user_meta($user_id, 'user_lastname', true) . ' (#' . $user_id . ' - ' . get_user_meta($user_id, 'user_email', true) . ')'; ?> if( $().select2 ){ jQuery("#customer_user").select2("data", {"id":"<?php echo $user_id; ?> ","text":"<?php echo $c_name; ?> "}); }else{ jQuery('#customer_user').append('<option selected="selected" value="<?php echo $user_id; ?> "><?php echo $c_name; ?> )</option>').val(<?php echo $user_id; ?> ).trigger('chosen:updated'); } <?php $customer_details = new WC_Crm_Customer_Details($user_id, 0); $customer_details->init_address_fields(); $__b_address = $customer_details->billing_fields; $__s_address = $customer_details->shipping_fields; $formatted_shipping_address = wp_kses($customer_details->get_formatted_shipping_address(), array("br" => array())); //$formatted_shipping_address = str_replace('<br />', '<br />\\', $formatted_shipping_address); $formatted_billing_address = wp_kses($customer_details->get_formatted_billing_address(), array("br" => array())); //$formatted_billing_address = str_replace('<br />', '<br />\\', $formatted_billing_address); foreach ($__b_address as $key => $field) { ?> jQuery('#_billing_<?php echo $key; ?> ').val( "<?php echo addslashes(get_user_meta($user_id, 'billing_' . $key, true)); ?> " ); <?php } foreach ($__s_address as $key => $field) { ?> jQuery('#_shipping_<?php echo $key; ?> ').val( "<?php echo addslashes(get_user_meta($user_id, 'shipping_' . $key, true)); ?> " ); <?php } ?> jQuery('.order_data_column_container .order_data_column').last().find('.address') .html("<?php echo "<p><strong>" . __("Address", "woocommerce") . ":</strong>" . addslashes($formatted_shipping_address) . "</p>"; ?> "); jQuery('.order_data_column_container .order_data_column').first().next().find('.address') .html("<?php echo "<p><strong>" . __("Address", "woocommerce") . ":</strong>" . addslashes($formatted_billing_address) . "</p>"; ?> "); <?php $js_string = ob_get_contents(); ob_end_clean(); wc_enqueue_js($js_string); } else { if (isset($_GET['post_type']) && $_GET['post_type'] == 'shop_order' && isset($_GET['last_order_id']) && !empty($_GET['last_order_id'])) { $last_order_id = $_GET['last_order_id']; ob_start(); $customer_details = new WC_Crm_Customer_Details(0, $last_order_id); $customer_details->init_address_fields(); $__b_address = $customer_details->billing_fields; $__s_address = $customer_details->shipping_fields; $formatted_shipping_address = wp_kses($customer_details->get_formatted_shipping_address(), array("br" => array())); $formatted_shipping_address = str_replace('<br />', '<br />\\', $formatted_shipping_address); $formatted_billing_address = wp_kses($customer_details->get_formatted_billing_address(), array("br" => array())); $formatted_billing_address = str_replace('<br />', '<br />\\', $formatted_billing_address); foreach ($__b_address as $key => $field) { $name_var = 'billing_' . $key; $field_val = $customer_details->order->{$name_var}; ?> jQuery('#_billing_<?php echo $key; ?> ').val( "<?php echo addslashes($field_val); ?> " ); <?php } foreach ($__s_address as $key => $field) { $name_var = 'shipping_' . $key; $field_val = $customer_details->order->{$name_var}; ?> jQuery('#_shipping_<?php echo $key; ?> ').val( "<?php echo addslashes($field_val); ?> " ); <?php } ?> jQuery('.order_data_column_container .order_data_column').last().find('.address') .html("<?php echo "<p><strong>" . __("Address", "woocommerce") . ":</strong>" . addslashes($formatted_shipping_address) . "</p>"; ?> "); jQuery('.order_data_column_container .order_data_column').first().next().find('.address') .html("<?php echo "<p><strong>" . __("Address", "woocommerce") . ":</strong>" . addslashes($formatted_billing_address) . "</p>"; ?> "); <?php $js_string = ob_get_contents(); ob_end_clean(); wc_enqueue_js($js_string); } } }
/** * Add customer note via ajax */ function add_customer_note() { $user_id = (int) $_POST['user_id']; $note = wp_kses_post(trim(stripslashes($_POST['note']))); if ($user_id > 0) { $comment_id = WC_Crm_Customer_Details::add_order_note($note, $user_id); echo '<li rel="' . esc_attr($comment_id) . '" class="note"><div class="note_content">'; echo wpautop(wptexturize($note)); echo '</div><p class="meta"><a href="#" class="delete_customer_note">' . __('Delete note', 'woocommerce') . '</a></p>'; echo '</li>'; } // Quit out die; }