@shivanand-sharma this is perfect and cleaner method (https://developer.wordpress.org/themes/template-files-section/page-template-files/) to create any page like any other in wordpress, and if you want to hide your page, i just use the simple and efective plugin 'https://wordpress.org/plugins/exclude-pages/'
I must say that i was in need of a URL to make POST or GET to my own page and save some session data 'WC()->session', and this solves this and other problems, because you can have a backbone of custom php code including all the 'require('wp-load') etc' of the entire wordpress, woocommerce etc to work with through, mysite.com/index.php/MYPAGE .....
You just need to :
First: Create a file inside your theme location as a template of the new page something like 'wp-content/themes/mytheme/customtemplate.php' (Comment is important so the 'Template Name' can be observed by Wordpress) :
<?php /* Template Name: WhateverName */
echo 'Hello World';echo '</br>';
var_dump(WC()->session);
var_dump($_POST);
var_dump($_GET);
?>
Second: Create a page at wordpress normally through 'wp-admin' > Pages (Let's say a name like MYPAGE, or you can change the slug whatever you want) and off course link the previous template as the template of this page which is name 'WhateverName' on the template attributtes section.
So, Let's open the new page 'mysite.com/index.php/MYPAGE' and you will see.
Hello World
object(WC_Session_Handler)#880 .....................
Extras: Let's create javascript or jquery functions in cart, checkout, whatever you can imagine inside 'script' HTML tags, and include code like this:
var data = { action : actionName, dataA : etcA, dataB : etcB}
$.ajax({
type: 'post',
url: 'index.php/MYPAGE',
data: data,
success: function( response ) {
},
complete: function() {
}
});
template_redirect
or an endpoint – s_ha_dum Mar 30 '15 at 15:29