Automattic\WooCommerce\Internal\Orders
OrderAttributionController::maybe_set_admin_source
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).
Method of the class: OrderAttributionController{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->maybe_set_admin_source( $order );
- $order(WC_Order) (required)
- The recently created order object.
Changelog
| Since 8.5.0 | Introduced. |
OrderAttributionController::maybe_set_admin_source() OrderAttributionController::maybe set admin source code WC 10.3.3
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();
}