LLMS_Order::set_user_data( array|LLMS_Student|WP_User|integer $user_or_data )

Sets user-related metadata for the order.


Parameters Parameters

$user_or_data

(array|LLMS_Student|WP_User|integer) (Required) Accepts a raw array user meta-data or an input string accepted by llms_get_student(). When passing an existing user the data will be pulled from the user metadata and saved to the order.


Top ↑

Return Return

(array) Returns an associative array representing the user metadata that was stored on the order.

  • 'user_id'
    (integer) User's WP_User id.
  • 'user_ip_address'
    (string) User's ip address.
  • 'billing_email'
    (string) User's email.
  • 'billing_first_name'
    (string) User's first name.
  • 'billing_last_name'
    (string) User's last name.
  • 'billing_address_1'
    (string) User's address line 1.
  • 'billing_address_2'
    (string) User's address line 2.
  • 'billing_city'
    (string) User's city.
  • 'billing_state'
    (string) User's state.
  • 'billing_zip'
    (string) User's zip.
  • 'billing_country'
    (string) User's country.
  • 'billing_phone'
    (string) User's phone.


Top ↑

Source Source

File: includes/models/model.llms.order.php

	public function set_user_data( $user_or_data ) {

		$to_set = array(
			'user_id'            => '',
			'billing_email'      => '',
			'billing_first_name' => '',
			'billing_last_name'  => '',
			'billing_address_1'  => '',
			'billing_address_2'  => '',
			'billing_city'       => '',
			'billing_state'      => '',
			'billing_zip'        => '',
			'billing_country'    => '',
			'billing_phone'      => '',
		);

		$user = ! is_array( $user_or_data ) ? llms_get_student( $user_or_data ) : false;
		if ( $user ) {

			$user_or_data = array();

			$map = array(
				'user_id'            => 'id',
				'billing_email'      => 'user_email',
				'billing_phone'      => 'phone',
				'billing_first_name' => 'first_name',
				'billing_last_name'  => 'last_name',
			);

			foreach ( array_keys( $to_set ) as $order_key ) {
				$to_set[ $order_key ] = $user->get( $map[ $order_key ] ?? $order_key );
			}
		}

		// Only use the default IP address if it wasn't specified in the input array.
		$to_set['user_ip_address'] = $user_or_data['user_ip_address'] ?? llms_get_ip_address();

		// Merge the data and remove excess keys.
		$to_set = array_intersect_key(
			array_merge( $to_set, $user_or_data ),
			$to_set
		);

		$this->set_bulk( $to_set );
		return $to_set;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.