admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aisp_assign_user_nonce' ), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aisp_assign_user_nonce' ), 'noUser' => esc_html__( 'No users found.', 'aisp-order-tools-for-woocommerce' ), 'searching' => esc_html__( 'Searching...', 'aisp-order-tools-for-woocommerce' ), 'assignedTo' => esc_html__( 'Assigned to:', 'aisp-order-tools-for-woocommerce' ), 'modifiedLabel' => esc_html__( '— billing data modified', 'aisp-order-tools-for-woocommerce' ), 'guestMode' => esc_html__( 'Guest order (no user assigned)', 'aisp-order-tools-for-woocommerce' ), 'useAsGuest' => esc_html__( 'Use as guest instead', 'aisp-order-tools-for-woocommerce' ), 'clearFields' => esc_html__( 'Clear all billing fields', 'aisp-order-tools-for-woocommerce' ), 'clearAll' => esc_html__( 'Clear all (guest mode)', 'aisp-order-tools-for-woocommerce' ), 'popupTitle' => esc_html__( 'Modify assigned customer?', 'aisp-order-tools-for-woocommerce' ), 'popupText' => esc_html__( 'You have modified the information of an assigned customer. If you continue, the customer will be removed and the order will be created in guest mode.', 'aisp-order-tools-for-woocommerce' ), 'popupYes' => esc_html__( 'Continue as guest', 'aisp-order-tools-for-woocommerce' ), 'popupCancel' => esc_html__( 'Keep assigned customer', 'aisp-order-tools-for-woocommerce' ), ] ); } public function block_admin_usermeta_overwrite( $check, $user_id, $meta_key, $meta_value, $prev_value ) { if ( strpos( $meta_key, 'billing_' ) !== 0 && strpos( $meta_key, 'shipping_' ) !== 0 ) { return null; } $user = get_user_by( 'id', $user_id ); if ( ! $user ) { return null; } if ( ! in_array( 'administrator', (array) $user->roles, true ) ) { return null; } if ( ! is_admin() ) { return true; } return null; } public function assign_order_to_user( $order, $data ) { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } if ( ! isset( $_POST['aisp_assign_user_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['aisp_assign_user_nonce'] ) ), 'aisp_assign_user_nonce' ) ) { return; } $assigned_user_id = 0; if ( isset( $_POST['aisp_otools_assign_user_id'] ) ) { $assigned_user_id = absint( wp_unslash( $_POST['aisp_otools_assign_user_id'] ) ); } $order->set_customer_id( $assigned_user_id ); if ( $assigned_user_id > 0 ) { foreach ( [ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state', 'billing_postcode', 'billing_country', 'billing_phone', 'billing_email', ] as $field ) { $getter = "get_$field"; if ( method_exists( $order, $getter ) ) { $value = $order->$getter(); if ( $value !== '' ) { update_user_meta( $assigned_user_id, $field, $value ); } } } $order->add_order_note( sprintf( // translators: #%d is user id (e.g 234) esc_html__( 'Order assigned to user ID #%d by admin (Safe Assign).', 'aisp-order-tools-for-woocommerce' ), $assigned_user_id ) ); } } }