diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index 76ed86f5d79..b2ab190c506 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -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 ); + } } diff --git a/includes/shortcodes/class-wc-shortcode-checkout.php b/includes/shortcodes/class-wc-shortcode-checkout.php index 366a775eac9..74d76922540 100644 --- a/includes/shortcodes/class-wc-shortcode-checkout.php +++ b/includes/shortcodes/class-wc-shortcode-checkout.php @@ -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(); }