Merge pull request #25137 from woocommerce/fix/24936

Only update the customer IP address when order gets created from admin
This commit is contained in:
Claudio Sanches 2020-01-30 19:41:08 -03:00 committed by GitHub
commit 0bec8443f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -2059,4 +2059,15 @@ class WC_Order extends WC_Abstract_Order {
return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this, $tax_display );
}
/**
* Check if order has been created via admin, checkout, or in another way.
*
* @since 4.0.0
* @param string $modus Way of creating the order to test for.
* @return bool
*/
public function is_created_via( $modus ) {
return apply_filters( 'woocommerce_order_is_created_via', $modus === $this->get_created_via(), $this, $modus );
}
}

View File

@ -236,8 +236,9 @@ class WC_Shortcode_Checkout {
// Empty awaiting payment session.
unset( WC()->session->order_awaiting_payment );
// In case order is created from admin, but paid by the actual customer, store the ip address of the payer.
if ( $order ) {
// In case order is created from admin, but paid by the actual customer, store the ip address of the payer
// when they visit the payment confirmation page.
if ( $order && $order->is_created_via( 'admin' ) ) {
$order->set_customer_ip_address( WC_Geolocation::get_ip_address() );
$order->save();
}