Automattic\WooCommerce\Internal\Orders

OrderAttributionController::maybe_set_admin_source()privateWC 8.5.0

If the order is created in the admin, set the source type and origin to admin/Web admin. Only execute this if the order is created in the admin interface (or via ajax in the admin interface).

Метод класса: OrderAttributionController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->maybe_set_admin_source( $order );
$order(WC_Order) (обязательный)
The recently created order object.

Список изменений

С версии 8.5.0 Введена.

Код OrderAttributionController::maybe_set_admin_source() WC 9.6.1

private function maybe_set_admin_source( WC_Order $order ) {

	// For ajax requests, bail if the referer is not an admin page.
	$http_referer     = esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ?? '' ) );
	$referer_is_admin = 0 === strpos( $http_referer, get_admin_url() );
	if ( ! $referer_is_admin && wp_doing_ajax() ) {
		return;
	}

	// If not admin interface page, bail.
	if ( ! is_admin() ) {
		return;
	}

	$order->add_meta_data( $this->get_meta_prefixed_field_name( 'source_type' ), 'admin' );
	$order->save();
}