So I created a new custom tab in My Account menu called "Shipping Tracking" and the content inside this page is the form-tracking.php template.
My problem is when I press the submit button to track an order it redirects me to my account dashboard page. So I tried to create an ajax form submission with no success based on this post WooCommerce track order submit AJAX
I don't mind if the form submission will be in ajax or with page refresh , I just want to stay in Shipping Tracking page
My code:
/*
* Step 1. Add Link (Tab) to My Account menu
*/
add_filter ( 'woocommerce_account_menu_items', 'shippingTracking_link', 40 );
function shippingTracking_link( $menu_links ){
$menu_links = array_slice( $menu_links, 0, 5, true )
+ array( 'shipping-tracking' => 'Shipping Tracking' )
+ array_slice( $menu_links, 5, NULL, true );
unset( $menu_links['downloads'] );
return $menu_links;
}
/*
* Step 2. Register Permalink Endpoint
*/
add_action( 'init', 'misha_add_endpoint' );
function misha_add_endpoint() {
// WP_Rewrite is my Achilles' heel, so please do not ask me for detailed explanation
add_rewrite_endpoint( 'shipping-tracking', EP_ROOT | EP_PAGES );
}
/*
* Step 3. Content for the new page in My Account, woocommerce_account_{ENDPOINT NAME}_endpoint
*/
add_action( 'woocommerce_account_shipping-tracking_endpoint', 'misha_my_account_endpoint_content' );
function misha_my_account_endpoint_content() {
//get the order tracking form template
wc_get_template( 'order/form-tracking.php' );
}
/*
* Step 4
*/
// Go to Settings > Permalinks and just push "Save Changes" button.
source https://stackoverflow.com/questions/70545801/submit-woocommerce-order-tracking-form-from-my-account-custom-tab
Comments
Post a Comment