woocommerce-plugin
woocommerce-plugin copied to clipboard
Custom URL routes
Hello,
my payment URL looks like
http://localhost/wc-api/WC_Gateway_Blockonomics/?show_order=1C8965rf2BP44Krtm2imutAXAfgFwt9Lth
and I want something like this
http://localhost/crypto/?show_order=1C8965rf2BP44Krtm2imutAXAfgFwt9Lth
Replace /wc-api/WC_Gateway_Blockonomics/ with /crypto/. That's all.
My functions.php looks like
add_action( 'init', 'wpse_rewrites_init' );
function wpse_rewrites_init(){
add_rewrite_rule(
'crypto/?show_order=([A-Za-z0-9]+)/?$',
//'wc-api=WC_Gateway_Blockonomics&show_order=$matches[1]',
'wc-api=WC_Gateway_Blockonomics&show_order=$1',
'top' );
}
Somebody on the internet suggested that $matches[1] doesn't work for external redirects, only internal. But anyways, it doesn't work for me.
I was told to consult this issue with Blockonomics dev Support (Here).
Thanks for taking out the time to try out our plugin and logging this. We are looking at this on priority
Hi @jozefpinter
I am having success using the below code:
/* Blockonomics Rewrite Rules */
add_action('init', 'blockonomics_rewrite_rules');
function blockonomics_rewrite_rules() {
add_rewrite_rule( 'crypto/?$', 'index.php?wc-api=WC_Gateway_Blockonomics', 'top' );
}
You will now be able to access the checkout page from
http://localhost/crypto/?show_order=1C8965rf2BP44Krtm2imutAXAfgFwt9Lth
However, more changes will still be required to forward the user to this new URL. I will update you here with this information, when available.
Hello @DarrenWestwood ,
exactly as you are saying. With your code I can access payment URL via new URL.
But I need get of rid of old URL because payment gateway is sending me there. So /wc-api/WC_Gateway_Blockonomics/ is still visible.
In the callback file here, we can add the following line:
$order_url = str_replace('wc-api/WC_Gateway_Blockonomics', 'crypto', $order_url);
This will now redirect the users to the new URL during the checkout process.
Please note, this change will need to be applied after updating the Blockonomics plugin.
@DarrenWestwood ,
can you update the callback in the plugin to redirect users to nicer URL (bitcoin, btc, crypto, whatever) instead /wc-api/WC_Gateway_Blockonomics/ ?
Because I think this is really weird URL. It will help to the plugin.
@jozefpinter, Could you verify the above changes are working correctly for you as well?
We are assessing this option further for possible inclusion into a later release. Thank you for this suggestion.
@DarrenWestwood , do you mean the code which goes into the file functions.php ? It is working fine, but you know... it not helps because plugin is sending me to /wc-api/WC_Gateway_Blockonomics/
or the second snippet of code which goes into the plugin? I didnt try it. Because if you update the plugin I will lose my own changes.
As we are still assessing the viability and compatibility of the changes for all our users, this integration will require more testing before being applied to plugin releases. If you require this feature instantly, you can apply the second snippet to the plugin directly (This will need to be done after updating the plugin). We would like you to test these new changes to validate they are working as desired.
@DarrenWestwood , my website is on localhost. I can't test it.
You are welcome to download the plugin with the above changes included from here: https://github.com/blockonomics/woocommerce-plugin/tree/custom-url-routes
or edit the plugin from the Wordpress Plugin Editor:

I didnt try it. Because if you update the plugin I will lose my own changes.
Yes we understand. Just to clarify we want to test if changes @DarrenWestwood mentioned are working. We are seriously considering adding this to the main plugin code soon, but first we need to test a little
@DarrenWestwood ,
I've added
$order_url = str_replace('wc-api/WC_Gateway_Blockonomics', 'crypto', $order_url);
via Plugin editor as you mentioned.
WAIT. Something is wrong here. I'll let you know.
UPDATE2:
It is sending me at new URL. That's OK.
http://localhost/crypto/?show_order=1H4BMmAZ5ndvhTzCPapMtHcntfyuvobNRJ
but after it redirects me at homepage. I am using a custom code to redirect 404.
So I've disabled a redirect for 404
if(is_404()) { //wp_redirect(home_url()); exit; }
Now it is sending me at new URL. Once again. That's OK.
http://localhost/crypto/?show_order=1H4BMmAZ5ndvhTzCPapMtHcntfyuvobNRJ
but WP is showing a message.
Oops! That page can’t be found. Nothing was found at this location. Try searching, or check out the links below.
I am not an expert, but it seems new payment URL is a 404 page.
UPDATE3: Now during the checkout I see (after I removed the line 142)
Unable to generate bitcoin address. Note for site webmaster: Please login to your admin panel, navigate to Settings > Blockonomics and click Test Setup to diagnose the issue
I click "Test setup" then "Save". It doesn't help.
@jozefpinter
Both snippets of code need to be applied for this change to work as desired.
- The
add_rewrite_rulemust be added, which you mention was working correctly to display the page via the new URL. $order_url = str_replace('wc-api/WC_Gateway_Blockonomics', 'crypto', $order_url);added to the plugin, to redirect users to the new page.
The plugin here has both changes applied in the plugin and is working correctly for me on localhost.

I click "Test setup" then "Save". It doesn't help.
Are you receiving an error message when clicking Test Setup?
Could you also visit Wordpress Dashboard > Settings > Permalink > and Click Save Changes.
This will flush rewrite rules for your website, in case other changes you may have made to rewrite rules are causing the issue.
@DarrenWestwood ,
-
Thanks, now it works. But I swear I tried it yesterday many times and it not worked. (test setup + save + flush rewrite rules) Today it is working.
-
OK. I will let you know.
Thank you @jozefpinter for assisting in testing this feature.
Thanks @jozefpinter we will try to add this in the upcoming release
@DarrenWestwood ,
It seems that it is working correctly for me. I've sent some test BTC. I had no issue. But remember, I am on localhost. This is not real environment.
This merge is deferred until we have a more time / is requested more. Please add a list of test cases to the ticket