[Tutorials] Change Email To Phone Number Tracking Woocommerce Orders

Change Email To Phone Number Tracking

[Tutorials] Change Email To Phone Number Tracking Woocommerce Orders

By default, the woocommerce order tracking form will have 2 data fields: Order ID and Email. There are many cases where customers enter a virtual email, which leads to when they want to check the order, they forget to remember the email so they can’t track it or for some reason the customer can’t access the email anymore, it’s also difficult to track.

Many of you want to replace the email field with a phone number for convenient tracking, so today Flatsomea-z will guide you to do it manually for your reference.

Step 1: Edit File class-wc-shortcode-order-tracking.php

You can access the following path:wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-order-tracking.php and search this code: if ( isset( $_REQUEST[‘orderid’] )

Delete that word to the end and replace it with this code:

if ( isset( $_REQUEST['orderid'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-order_tracking' ) ) { // WPCS: input var ok.

$order_id = empty( $_REQUEST['orderid'] ) ? 0 : ltrim( wc_clean( wp_unslash( $_REQUEST['orderid'] ) ), '#' ); // WPCS: input var ok.
$order_phone = empty( $_REQUEST['order_phone'] ) ? '' : ( wc_sanitize_phone_number( $_REQUEST['order_phone'] ) ); // WPCS: input var ok.

if ( ! $order_id ) {
wc_print_notice( __( 'Please enter a valid order ID', 'woocommerce' ), 'error' );
} elseif ( ! $order_phone ) {
wc_print_notice( __( 'Please enter a valid phone number', 'woocommerce' ), 'error' );
} else {
$order = wc_get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );

if ( $order && $order->get_id() && wc_sanitize_phone_number( $order->get_billing_phone() ) === $order_phone ) {
do_action( 'woocommerce_track_order', $order->get_id() );
wc_get_template(
'order/tracking.php',
array(
'order' => $order,
)
);
return;
} else {
wc_print_notice( __( 'Sorry, the order could not be found. Please contact us if you are having difficulty finding your order details.', 'woocommerce' ), 'error' );
}
}
}
wc_get_template( 'order/form-tracking.php' );
}
}

Step 2: Edit File form-tracking.php

You can access the following path: wp-content/plugins/woocommerce/templates/order/form-tracking.php and search this code: <p class=”form-row form-row-last”>.Replace that whole paragraph with the following code:

<p class="form-row form-row-last"><label for="order_phone"><?php esc_html_e( 'Số điện thoại đặt hàng', 'woocommerce' ); ?></label> <input class="input-text" type="text" name="order_phone" id="order_phone" value="<?php echo isset( $_REQUEST['order_phone'] ) ? esc_attr( wc_sanitize_phone_number( $_REQUEST['order_phone'] ) ) : ''; ?>" placeholder="<?php esc_attr_e( 'Nhập số điện thoại khi thanh toán', 'woocommerce' ); ?>" /></p><?php // @codingStandardsIgnoreLine ?>

Tested and successful! Good luck.

Trả lời

Email của bạn sẽ không được hiển thị công khai.