get_var( "SELECT COUNT(*) FROM $wpdb->posts as posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_customer_user' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ( 'completed' ) AND meta_value = $user_id " ); update_user_meta( $user_id, '_order_count', $count ); } $value = '' . absint( $count ) . ''; break; case "woocommerce_billing_address" : $address = array( 'first_name' => get_user_meta( $user_id, 'billing_first_name', true ), 'last_name' => get_user_meta( $user_id, 'billing_last_name', true ), 'company' => get_user_meta( $user_id, 'billing_company', true ), 'address_1' => get_user_meta( $user_id, 'billing_address_1', true ), 'address_2' => get_user_meta( $user_id, 'billing_address_2', true ), 'city' => get_user_meta( $user_id, 'billing_city', true ), 'state' => get_user_meta( $user_id, 'billing_state', true ), 'postcode' => get_user_meta( $user_id, 'billing_postcode', true ), 'country' => get_user_meta( $user_id, 'billing_country', true ) ); $formatted_address = $woocommerce->countries->get_formatted_address( $address ); if ( ! $formatted_address ) $value = __( 'N/A', 'woocommerce' ); else $value = $formatted_address; $value = wpautop( $value ); break; case "woocommerce_shipping_address" : $address = array( 'first_name' => get_user_meta( $user_id, 'shipping_first_name', true ), 'last_name' => get_user_meta( $user_id, 'shipping_last_name', true ), 'company' => get_user_meta( $user_id, 'shipping_company', true ), 'address_1' => get_user_meta( $user_id, 'shipping_address_1', true ), 'address_2' => get_user_meta( $user_id, 'shipping_address_2', true ), 'city' => get_user_meta( $user_id, 'shipping_city', true ), 'state' => get_user_meta( $user_id, 'shipping_state', true ), 'postcode' => get_user_meta( $user_id, 'shipping_postcode', true ), 'country' => get_user_meta( $user_id, 'shipping_country', true ) ); $formatted_address = $woocommerce->countries->get_formatted_address( $address ); if ( ! $formatted_address ) $value = __( 'N/A', 'woocommerce' ); else $value = $formatted_address; $value = wpautop( $value ); break; case "woocommerce_paying_customer" : $paying_customer = get_user_meta( $user_id, 'paying_customer', true ); if ( $paying_customer ) $value = ''; else $value = ''; break; endswitch; return $value; } add_action( 'manage_users_custom_column', 'woocommerce_user_column_values', 10, 3 ); /** * Get Address Fields for the edit user pages. * * @access public * @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned */ function woocommerce_get_customer_meta_fields() { $show_fields = apply_filters('woocommerce_customer_meta_fields', array( 'billing' => array( 'title' => __( 'Customer Billing Address', 'woocommerce' ), 'fields' => array( 'billing_first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'description' => '' ), 'billing_last_name' => array( 'label' => __( 'Last name', 'woocommerce' ), 'description' => '' ), 'billing_company' => array( 'label' => __( 'Company', 'woocommerce' ), 'description' => '' ), 'billing_address_1' => array( 'label' => __( 'Address 1', 'woocommerce' ), 'description' => '' ), 'billing_address_2' => array( 'label' => __( 'Address 2', 'woocommerce' ), 'description' => '' ), 'billing_city' => array( 'label' => __( 'City', 'woocommerce' ), 'description' => '' ), 'billing_postcode' => array( 'label' => __( 'Postcode', 'woocommerce' ), 'description' => '' ), 'billing_state' => array( 'label' => __( 'State/County', 'woocommerce' ), 'description' => __( 'Country or state code', 'woocommerce' ), ), 'billing_country' => array( 'label' => __( 'Country', 'woocommerce' ), 'description' => __( '2 letter Country code', 'woocommerce' ), ), 'billing_phone' => array( 'label' => __( 'Telephone', 'woocommerce' ), 'description' => '' ), 'billing_email' => array( 'label' => __( 'Email', 'woocommerce' ), 'description' => '' ) ) ), 'shipping' => array( 'title' => __( 'Customer Shipping Address', 'woocommerce' ), 'fields' => array( 'shipping_first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'description' => '' ), 'shipping_last_name' => array( 'label' => __( 'Last name', 'woocommerce' ), 'description' => '' ), 'shipping_company' => array( 'label' => __( 'Company', 'woocommerce' ), 'description' => '' ), 'shipping_address_1' => array( 'label' => __( 'Address 1', 'woocommerce' ), 'description' => '' ), 'shipping_address_2' => array( 'label' => __( 'Address 2', 'woocommerce' ), 'description' => '' ), 'shipping_city' => array( 'label' => __( 'City', 'woocommerce' ), 'description' => '' ), 'shipping_postcode' => array( 'label' => __( 'Postcode', 'woocommerce' ), 'description' => '' ), 'shipping_state' => array( 'label' => __( 'State/County', 'woocommerce' ), 'description' => __( 'State/County or state code', 'woocommerce' ) ), 'shipping_country' => array( 'label' => __( 'Country', 'woocommerce' ), 'description' => __( '2 letter Country code', 'woocommerce' ) ) ) ) )); return $show_fields; } /** * Show Address Fields on edit user pages. * * @access public * @param mixed $user User (object) being displayed * @return void */ function woocommerce_customer_meta_fields( $user ) { if ( ! current_user_can( 'manage_woocommerce' ) ) return; $show_fields = woocommerce_get_customer_meta_fields(); foreach( $show_fields as $fieldset ) : ?>
|