�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: class-wc-customer-data-store.php Size: 22.92 KB
/home2/astrociv/public_html/rudraraksham.com/wp-content/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php
<?php
/**
 * Class WC_Customer_Data_Store file.
 *
 * @package WooCommerce\DataStores
 */

use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Internal\Utilities\Users;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * WC Customer Data Store.
 *
 * @version  3.0.0
 */
class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Data_Store_Interface, WC_Object_Data_Store_Interface {

	/**
	 * Data stored in meta keys, but not considered "meta".
	 *
	 * @since 3.0.0
	 * @var array
	 */
	protected $internal_meta_keys = array(
		'locale',
		'billing_postcode',
		'billing_city',
		'billing_address_1',
		'billing_address_2',
		'billing_state',
		'billing_country',
		'shipping_postcode',
		'shipping_city',
		'shipping_address_1',
		'shipping_address_2',
		'shipping_state',
		'shipping_country',
		'paying_customer',
		'last_update',
		'first_name',
		'last_name',
		'display_name',
		'show_admin_bar_front',
		'use_ssl',
		'admin_color',
		'rich_editing',
		'comment_shortcuts',
		'dismissed_wp_pointers',
		'show_welcome_panel',
		'session_tokens',
		'nickname',
		'description',
		'billing_first_name',
		'billing_last_name',
		'billing_company',
		'billing_phone',
		'billing_email',
		'shipping_first_name',
		'shipping_last_name',
		'shipping_company',
		'shipping_phone',
		'wptests_capabilities',
		'wptests_user_level',
		'syntax_highlighting',
		'_order_count',
		'_money_spent',
		'_last_order',
		'_woocommerce_tracks_anon_id',
	);

	/**
	 * Internal meta type used to store user data.
	 *
	 * @var string
	 */
	protected $meta_type = 'user';

	/**
	 * Callback to remove unwanted meta data.
	 *
	 * @param object $meta Meta object.
	 * @return bool
	 */
	protected function exclude_internal_meta_keys( $meta ) {
		global $wpdb;

		$table_prefix = $wpdb->prefix ? $wpdb->prefix : 'wp_';

		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true )
			&& 0 !== strpos( $meta->meta_key, '_woocommerce_persistent_cart' )
			&& 0 !== strpos( $meta->meta_key, 'closedpostboxes_' )
			&& 0 !== strpos( $meta->meta_key, 'metaboxhidden_' )
			&& 0 !== strpos( $meta->meta_key, 'manageedit-' )
			&& ! strstr( $meta->meta_key, $table_prefix )
			&& 0 !== stripos( $meta->meta_key, 'wp_' );
	}

	/**
	 * Method to create a new customer in the database.
	 *
	 * @since 3.0.0
	 *
	 * @param WC_Customer $customer Customer object.
	 *
	 * @throws WC_Data_Exception If unable to create new customer.
	 */
	public function create( &$customer ) {
		$id = wc_create_new_customer( $customer->get_email(), $customer->get_username(), $customer->get_password() );

		if ( is_wp_error( $id ) ) {
			throw new WC_Data_Exception( $id->get_error_code(), $id->get_error_message() );
		}

		$customer->set_id( $id );

		// Sync back the user data from the created WP user in case it was auto-generated.
		$wp_user = new WP_User( $id );
		if ( $wp_user->exists() ) {
			$customer->set_username( $wp_user->user_login );
			$customer->set_date_created( $wp_user->user_registered );
		}

		$this->update_user_meta( $customer );

		// Prevent wp_update_user calls in the same request and customer trigger the 'Notice of Password Changed' email.
		$customer->set_password( '' );

		wp_update_user(
			apply_filters(
				'woocommerce_update_customer_args',
				array(
					'ID'           => $customer->get_id(),
					'role'         => $customer->get_role(),
					'display_name' => $customer->get_display_name(),
				),
				$customer
			)
		);
		$customer->set_date_modified( get_user_meta( $customer->get_id(), 'last_update', true ) );
		$customer->save_meta_data();
		$customer->apply_changes();
		do_action( 'woocommerce_new_customer', $customer->get_id(), $customer );
	}

	/**
	 * Method to read a customer object.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 * @throws Exception If invalid customer.
	 */
	public function read( &$customer ) {
		$user_object = $customer->get_id() ? get_user_by( 'id', $customer->get_id() ) : false;

		// User object is required.
		if ( ! $user_object || empty( $user_object->ID ) ) {
			throw new Exception( __( 'Invalid customer.', 'woocommerce' ) );
		}

		$customer_id = $customer->get_id();

		// Load meta but exclude deprecated props and parent keys.
		$user_meta = array_diff_key(
			array_change_key_case( array_map( 'wc_flatten_meta_callback', get_user_meta( $customer_id ) ) ),
			array_flip( array( 'country', 'state', 'postcode', 'city', 'address', 'address_2', 'default', 'location' ) ),
			array_change_key_case( (array) $user_object->data )
		);

		$customer->set_props( $user_meta );
		$customer->set_props(
			array(
				'is_paying_customer' => get_user_meta( $customer_id, 'paying_customer', true ),
				'email'              => $user_object->user_email,
				'username'           => $user_object->user_login,
				'display_name'       => $user_object->display_name,
				'date_created'       => $user_object->user_registered, // Mysql string in local format.
				'date_modified'      => get_user_meta( $customer_id, 'last_update', true ),
				'role'               => ! empty( $user_object->roles[0] ) ? $user_object->roles[0] : 'customer',
			)
		);
		$customer->read_meta_data();
		$customer->set_object_read( true );
		do_action( 'woocommerce_customer_loaded', $customer );
	}

	/**
	 * Updates a customer in the database.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 */
	public function update( &$customer ) {
		wp_update_user(
			apply_filters(
				'woocommerce_update_customer_args',
				array(
					'ID'           => $customer->get_id(),
					'user_email'   => $customer->get_email(),
					'display_name' => $customer->get_display_name(),
				),
				$customer
			)
		);

		// Only update password if a new one was set with set_password.
		if ( $customer->get_password() ) {
			wp_update_user(
				array(
					'ID'        => $customer->get_id(),
					'user_pass' => $customer->get_password(),
				)
			);
			$customer->set_password( '' );
		}

		$this->update_user_meta( $customer );
		$customer->set_date_modified( get_user_meta( $customer->get_id(), 'last_update', true ) );
		$customer->save_meta_data();
		$customer->apply_changes();
		do_action( 'woocommerce_update_customer', $customer->get_id(), $customer );
	}

	/**
	 * Deletes a customer from the database.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 * @param array       $args Array of args to pass to the delete method.
	 */
	public function delete( &$customer, $args = array() ) {
		if ( ! $customer->get_id() ) {
			return;
		}

		$args = wp_parse_args(
			$args,
			array(
				'reassign' => 0,
			)
		);

		$id = $customer->get_id();
		wp_delete_user( $id, $args['reassign'] );

		do_action( 'woocommerce_delete_customer', $id );
	}

	/**
	 * Helper method that updates all the meta for a customer. Used for update & create.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 */
	private function update_user_meta( $customer ) {
		$updated_props = array();
		$changed_props = $customer->get_changes();

		$meta_key_to_props = array(
			'paying_customer' => 'is_paying_customer',
			'first_name'      => 'first_name',
			'last_name'       => 'last_name',
		);

		foreach ( $meta_key_to_props as $meta_key => $prop ) {
			if ( ! array_key_exists( $prop, $changed_props ) ) {
				continue;
			}

			if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
				$updated_props[] = $prop;
			}
		}

		$billing_address_props = array(
			'billing_first_name' => 'billing_first_name',
			'billing_last_name'  => 'billing_last_name',
			'billing_company'    => 'billing_company',
			'billing_address_1'  => 'billing_address_1',
			'billing_address_2'  => 'billing_address_2',
			'billing_city'       => 'billing_city',
			'billing_state'      => 'billing_state',
			'billing_postcode'   => 'billing_postcode',
			'billing_country'    => 'billing_country',
			'billing_email'      => 'billing_email',
			'billing_phone'      => 'billing_phone',
		);

		foreach ( $billing_address_props as $meta_key => $prop ) {
			$prop_key = substr( $prop, 8 );

			if ( ! isset( $changed_props['billing'] ) || ! array_key_exists( $prop_key, $changed_props['billing'] ) ) {
				continue;
			}

			if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
				$updated_props[] = $prop;
			}
		}

		$shipping_address_props = array(
			'shipping_first_name' => 'shipping_first_name',
			'shipping_last_name'  => 'shipping_last_name',
			'shipping_company'    => 'shipping_company',
			'shipping_address_1'  => 'shipping_address_1',
			'shipping_address_2'  => 'shipping_address_2',
			'shipping_city'       => 'shipping_city',
			'shipping_state'      => 'shipping_state',
			'shipping_postcode'   => 'shipping_postcode',
			'shipping_country'    => 'shipping_country',
			'shipping_phone'      => 'shipping_phone',
		);

		foreach ( $shipping_address_props as $meta_key => $prop ) {
			$prop_key = substr( $prop, 9 );

			if ( ! isset( $changed_props['shipping'] ) || ! array_key_exists( $prop_key, $changed_props['shipping'] ) ) {
				continue;
			}

			if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
				$updated_props[] = $prop;
			}
		}

		do_action( 'woocommerce_customer_object_updated_props', $customer, $updated_props );
	}

	/**
	 * Check if the usage of the custom orders table is enabled.
	 *
	 * @return bool
	 */
	private function is_cot_in_use(): bool {
		return wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled();
	}

	/**
	 * Gets the customers last order.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 * @return WC_Order|false
	 */
	public function get_last_order( &$customer ) {
		// Try to fetch the last order placed by this customer.
		$customer_id         = $customer->get_id();
		$last_order_id       = Users::get_site_user_meta( $customer_id, 'wc_last_order', true );
		$last_customer_order = false;

		if ( ! empty( $last_order_id ) ) {
			$last_customer_order = wc_get_order( $last_order_id );
		}

		// "Unset" the last order ID if the order is associated with another customer. Unsetting is done by making it an
		// empty string, for compatibility with the declared types of the following filter hook.
		if (
			! $last_customer_order instanceof WC_Order
			|| intval( $last_customer_order->get_customer_id() ) !== intval( $customer_id )
		) {
			$last_order_id = '';
		}

		/**
		 * Filters the id of the last order from a given customer.
		 *
		 * @since 4.9.1
		 *
		 * @param string      $last_order_id The last order id as retrieved from the database.
		 * @param WC_Customer $customer      The customer whose last order id is being retrieved.
		 *
		 * @return string The actual last order id to use.
		 */
		$last_order_id = apply_filters(
			'woocommerce_customer_get_last_order',
			$last_order_id,
			$customer
		);
		//phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment

		if ( '' === $last_order_id ) {
			global $wpdb;

			$order_statuses_sql = "( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )";

			//phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			if ( $this->is_cot_in_use() ) {
				$sql           = $wpdb->prepare(
					"SELECT id FROM %i WHERE customer_id = %d AND status IN $order_statuses_sql ORDER BY id DESC LIMIT 1",
					OrdersTableDataStore::get_orders_table_name(),
					$customer_id
				);
				$last_order_id = $wpdb->get_var( $sql );
			} else {
				$last_order_id = $wpdb->get_var(
					"SELECT posts.ID
				FROM {$wpdb->posts} AS posts
				LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
				WHERE meta.meta_key   = '_customer_user'
				AND   meta.meta_value = '" . esc_sql( $customer_id ) . "'
				AND   posts.post_type = 'shop_order'
				AND   posts.post_status IN $order_statuses_sql
				ORDER BY posts.ID DESC
				LIMIT 1"
				);
			}
			//phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			Users::update_site_user_meta( $customer_id, 'wc_last_order', $last_order_id );
		}

		if ( ! $last_order_id ) {
			return false;
		}

		return wc_get_order( absint( $last_order_id ) );
	}

	/**
	 * Return the number of orders this customer has.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 * @return integer
	 */
	public function get_order_count( &$customer ) {
		$customer_id = $customer->get_id();
		/**
		 * Filters total orders count value for a given customer.
		 *
		 * @since 4.9.0
		 *
		 * @param mixed       $order_count The cached order count (from user meta).
		 * @param WC_Customer $customer    The customer to get the orders count for.
		 * @return mixed      The actual value to use.
		 */
		$count = apply_filters(
			'woocommerce_customer_get_order_count',
			Users::get_site_user_meta( $customer_id, 'wc_order_count', true ),
			$customer
		);

		$order_statuses_sql = "( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )";

		if ( '' === $count ) {
			global $wpdb;

			//phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			if ( $this->is_cot_in_use() ) {
				$sql   = $wpdb->prepare(
					"SELECT COUNT(id) FROM %i WHERE customer_id = %d AND status IN $order_statuses_sql",
					OrdersTableDataStore::get_orders_table_name(),
					$customer_id
				);
				$count = $wpdb->get_var( $sql );
			} else {
				$count = $wpdb->get_var(
					"SELECT COUNT(*)
				FROM {$wpdb->posts} as posts
				LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
				WHERE   meta.meta_key   = '_customer_user'
				AND     posts.post_type = 'shop_order'
				AND     posts.post_status IN $order_statuses_sql
				AND     meta_value = '" . esc_sql( $customer_id ) . "'"
				);
			}
			//phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared

			Users::update_site_user_meta( $customer_id, 'wc_order_count', $count );
		}

		return absint( $count );
	}

	/**
	 * Return how much money this customer has spent.
	 *
	 * @since 3.0.0
	 * @param WC_Customer $customer Customer object.
	 * @return float
	 */
	public function get_total_spent( &$customer ) {
		$customer_id = $customer->get_id();
		/**
		 * Filters total spent value for a given customer.
		 *
		 * @since 3.1.0
		 *
		 * @param mixed       $money_spent The cached money spent value (from user meta).
		 * @param WC_Customer $customer    The customer to get the total spent for.
		 * @return mixed      The actual value to use.
		 */
		$spent = apply_filters(
			'woocommerce_customer_get_total_spent',
			Users::get_site_user_meta( $customer_id, 'wc_money_spent', true ),
			$customer
		);

		if ( '' === $spent ) {
			global $wpdb;

			$statuses     = array_map( 'esc_sql', wc_get_is_paid_statuses() );
			$statuses_sql = "( 'wc-" . implode( "','wc-", $statuses ) . "' )";

			//phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			if ( $this->is_cot_in_use() ) {
				$sql = $wpdb->prepare(
					"SELECT SUM(total_amount) FROM %i WHERE customer_id = %d AND status IN $statuses_sql",
					OrdersTableDataStore::get_orders_table_name(),
					$customer_id
				);
			} else {
				$has_sql_modification_filter = has_filter( 'woocommerce_customer_get_total_spent_query' );
				if ( $has_sql_modification_filter ) {
					// For backward compatibility: external filters might rely onto the query structure.
					$sql = "SELECT SUM(meta2.meta_value)
					FROM {$wpdb->posts} as posts
					LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
					LEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id
					WHERE   meta.meta_key       = '_customer_user'
					AND     meta.meta_value     = '" . esc_sql( $customer_id ) . "'
					AND     posts.post_type     = 'shop_order'
					AND     posts.post_status   IN $statuses_sql
					AND     meta2.meta_key      = '_order_total'";
				} else {
					$sql = "SELECT SUM(postmeta.meta_value)
					FROM {$wpdb->posts} AS posts
					LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
					WHERE posts.ID IN (
								SELECT posts.ID as order_id
								FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
								WHERE postmeta.meta_key   = '_customer_user'
								  AND postmeta.meta_value = '" . esc_sql( $customer_id ) . "'
								  AND posts.post_type     = 'shop_order'
								  AND posts.post_status IN $statuses_sql
					)
					AND postmeta.meta_key = '_order_total'";
				}
			}

			/**
			 * Filters the SQL query used to get the combined total of all the orders from a given customer.
			 *
			 * @since 3.1.0
			 *
			 * @param string      $sql      The SQL query to use.
			 * @param WC_Customer $customer The customer to get the total spent for.
			 * @return string     The actual SQL query to use.
			 */
			$sql = apply_filters( 'woocommerce_customer_get_total_spent_query', $sql, $customer );

			$spent = $wpdb->get_var( $sql );
			//phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared

			if ( ! $spent ) {
				$spent = 0;
			}
			Users::update_site_user_meta( $customer_id, 'wc_money_spent', $spent );
		}

		return wc_format_decimal( $spent, 2 );
	}

	/**
	 * Search customers and return customer IDs.
	 *
	 * @param  string     $term Search term.
	 * @param  int|string $limit Limit search results.
	 * @since 3.0.7
	 *
	 * @return array
	 */
	public function search_customers( $term, $limit = '' ) {
		$results = apply_filters( 'woocommerce_customer_pre_search_customers', false, $term, $limit );
		if ( is_array( $results ) ) {
			return $results;
		}

		$query = new WP_User_Query(
			apply_filters(
				'woocommerce_customer_search_customers',
				array(
					'search'         => '*' . esc_attr( $term ) . '*',
					'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ),
					'fields'         => 'ID',
					'number'         => $limit,
				),
				$term,
				$limit,
				'main_query'
			)
		);

		$query2 = new WP_User_Query(
			apply_filters(
				'woocommerce_customer_search_customers',
				array(
					'fields'     => 'ID',
					'number'     => $limit,
					'meta_query' => array(
						'relation' => 'OR',
						array(
							'key'     => 'first_name',
							'value'   => $term,
							'compare' => 'LIKE',
						),
						array(
							'key'     => 'last_name',
							'value'   => $term,
							'compare' => 'LIKE',
						),
					),
				),
				$term,
				$limit,
				'meta_query'
			)
		);

		$results = wp_parse_id_list( array_merge( (array) $query->get_results(), (array) $query2->get_results() ) );

		if ( $limit && count( $results ) > $limit ) {
			$results = array_slice( $results, 0, $limit );
		}

		return $results;
	}

	/**
	 * Get all user ids who have `billing_email` set to any of the email passed in array.
	 *
	 * @deprecated since 10.3.0 and not used by WooCommerce core anymore.
	 *
	 * @param array $emails List of emails to check against.
	 *
	 * @return array
	 */
	public function get_user_ids_for_billing_email( $emails ) {
		wc_deprecated_function( __METHOD__, '10.3.0' );
		$emails      = array_unique( array_map( 'strtolower', array_map( 'sanitize_email', $emails ) ) );
		$users_query = new WP_User_Query(
			array(
				'fields'     => 'ID',
				'meta_query' => array(
					array(
						'key'     => 'billing_email',
						'value'   => $emails,
						'compare' => 'IN',
					),
				),
			)
		);
		return array_unique( $users_query->get_results() );
	}

	/**
	 * Query customers ordered by allowed fields.
	 *
	 * @param array $args Query arguments.
	 * @return object Object containing customers in the requested order, total, and max_num_pages.
	 */
	public function query_customers( array $args = array() ) {
		global $wpdb;
		$site_specific_key = rtrim( $wpdb->get_blog_prefix( get_current_blog_id() ), '_' );

		$defaults = array(
			'order'    => 'asc',
			'orderby'  => 'registered_date',
			'per_page' => 10,
			'page'     => 1,
			'search'   => '',
			'role'     => 'customer',
			'include'  => array(),
			'exclude'  => array(),
		);

		$args        = wp_parse_args( $args, $defaults );
		$orderby_key = $args['orderby'];

		// Set order parameter to asc/desc if somehow made it here without being caught earlier.
		$args['order'] = strtolower( $args['order'] );
		if ( ! in_array( $args['order'], array( 'asc', 'desc' ), true ) ) {
			$args['order'] = 'asc';
		}

		$query_args = array(
			'order'   => $args['order'],
			'number'  => absint( $args['per_page'] ),
			'exclude' => array_map( 'absint', (array) $args['exclude'] ),
			'include' => array_map( 'absint', (array) $args['include'] ),
		);

		$query_args['offset'] = ( max( 1, intval( $args['page'] ) ) - 1 ) * $query_args['number'];

		if ( ! empty( $args['search'] ) ) {
			$search                       = sanitize_text_field( $args['search'] );
			$query_args['search']         = $search;
			$query_args['search_columns'] = array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' );
		}

		switch ( $orderby_key ) {
			case 'ID':
				$query_args['orderby'] = 'ID';
				break;
			case 'display_name':
				$query_args['orderby'] = 'display_name';
				break;
			case 'wc_order_count':
				$query_args['meta_key'] = 'wc_order_count_' . $site_specific_key; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
				$query_args['orderby']  = 'meta_value_num';
				break;
			case 'wc_money_spent':
				$query_args['meta_key'] = 'wc_money_spent_' . $site_specific_key; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
				$query_args['orderby']  = 'meta_value_num';
				break;
			case 'wc_last_active':
				$query_args['meta_key'] = 'wc_last_active'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
				$query_args['orderby']  = 'meta_value_num';
				break;
			case 'user_registered':
			case 'registered_date':
				$query_args['orderby'] = 'user_registered';
				break;
			default:
				$query_args['orderby'] = 'user_registered';
				break;
		}

		// Only add role filter if role is 'customer' (not 'all' or empty).
		if ( 'customer' === $args['role'] ) {
			$query_args['role'] = 'customer';
		}

		/**
		 * Filter customer query args before execution.
		 *
		 * @since 10.4.0
		 *
		 * @param array $query_args Arguments for WP_User_Query.
		 * @param array $args       Original method args.
		 */
		$query_args = apply_filters( 'woocommerce_customer_query_args', $query_args, $args );

		// Ensure number is positive.
		$query_args['number'] = absint( intval( $query_args['number'] ) <= 0 ? $defaults['per_page'] : $query_args['number'] );

		$wp_user_query = new \WP_User_Query( $query_args );

		$customers = array();
		foreach ( $wp_user_query->get_results() as $user ) {
			$customers[] = new \WC_Customer( $user->ID );
		}

		return (object) array(
			'customers'     => $customers,
			'total'         => $wp_user_query->total_users,
			// Query args 'number' is always > 0 due to absint above.
			'max_num_pages' => ceil( $wp_user_query->total_users / $query_args['number'] ),
		);
	}
}

Directory Contents

Dirs: 0 × Files: 23
Name Size Perms Modified Actions
39.84 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
7.13 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
26.59 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
7.69 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
22.92 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
16.16 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
7.55 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
19.75 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
46.87 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
1.54 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
5.00 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
2.00 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
3.13 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
2.19 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
2.24 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
4.18 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
10.42 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
85.06 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
2.91 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
38.77 KB lrw-r--r-- 2026-07-28 11:37:06
Edit Download
23.80 KB lrw-r--r-- 2026-07-28 11:37:07
Edit Download
15.05 KB lrw-r--r-- 2026-07-28 11:37:07
Edit Download
14.60 KB lrw-r--r-- 2026-07-28 11:37:07
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI