Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom URL routes #154

Open
jozefpinter opened this issue Oct 3, 2019 · 19 comments
Open

Custom URL routes #154

jozefpinter opened this issue Oct 3, 2019 · 19 comments
Assignees

Comments

@jozefpinter
Copy link

jozefpinter commented Oct 3, 2019

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).

@blockonomics
Copy link
Owner

Thanks for taking out the time to try out our plugin and logging this. We are looking at this on priority

@DarrenWestwood
Copy link
Collaborator

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.

@jozefpinter
Copy link
Author

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.

@DarrenWestwood
Copy link
Collaborator

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.

@jozefpinter
Copy link
Author

@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.

@DarrenWestwood
Copy link
Collaborator

@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.

@jozefpinter
Copy link
Author

@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.

@DarrenWestwood
Copy link
Collaborator

DarrenWestwood commented Oct 8, 2019

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.

@jozefpinter
Copy link
Author

@DarrenWestwood , my website is on localhost. I can't test it.

@DarrenWestwood
Copy link
Collaborator

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:
Edit Plugins ‹ Wordpress — WordPress

@blockonomics
Copy link
Owner

blockonomics commented Oct 9, 2019

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

@jozefpinter
Copy link
Author

jozefpinter commented Oct 9, 2019

@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.

@DarrenWestwood
Copy link
Collaborator

@jozefpinter

Both snippets of code need to be applied for this change to work as desired.

  1. The add_rewrite_rule must be added, which you mention was working correctly to display the page via the new URL.
  2. $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.
Screenshot from 2019-10-10 15-11-27

I click "Test setup" then "Save". It doesn't help.

Are you receiving an error message when clicking Test Setup?

@DarrenWestwood
Copy link
Collaborator

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.

@jozefpinter
Copy link
Author

@DarrenWestwood ,

  1. 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.

  2. OK. I will let you know.

@DarrenWestwood
Copy link
Collaborator

Thank you @jozefpinter for assisting in testing this feature.

@blockonomics
Copy link
Owner

Thanks @jozefpinter we will try to add this in the upcoming release

@jozefpinter
Copy link
Author

@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.

@blockonomics
Copy link
Owner

This merge is deferred until we have a more time / is requested more. Please add a list of test cases to the ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants