Payment Gateway adding language url (Wordpress/Pol

2019-08-07 08:47发布

问题:

I have a Wordpress Website running Woocommerce. The website is available in 3 different languages. I Run the Polylang Plugin. I have a payment Gateway called Europabank. When i order a product and select this gateway everything works perfectly. I can pay the given amount and the payment is succesful. But after the payment the user gets redirected to the website confirmation page. The plugin handles this with the following code:

'feedbackurl' => WC ()->api_request_url ( 'WC_Gateway_EuropabankMpi' ),
'redirecturl' => WC ()->api_request_url ( 'WC_Gateway_EuropabankMpi' ), 

After the payment the url will look like this:

http://my-website-url.com/wc-api/WC_Gateway_EuropabankMpi/?somedata

This url will give a 404 error because the language is not provided, when i change the url into: (added /en/)

http://my-website-url.com/en/wc-api/WC_Gateway_EuropabankMpi/?somedata

will work. So i need to add the language code to the url. Which i can do with:

<?php  $currentlang = get_bloginfo('language');
                switch ($currentlang) {
                case "nl-NL":
                echo "/nl/";
                break;
                case "fr-FR":
                echo '/fr/';
                break;
                case "en-GB":
                echo '/en/';
                break;
                default: echo '/en/';
        };?>

Question

Where do i have to add this code? I don't mind changing the Plugin directly cause it will not need to be updated, but if you have a update proof solution that would be obviously better.

Plugin Versions & links

  • Wordpress : Version 4.4.1
  • Woocommerce: Version 2.4.12
  • Polylang : Version 1.7.12
  • Europabank MPI : Version 1.0

回答1:

Thank you Rophil_PHPBeginner for pointing out the correct place to put it.

Working code in woocommerce.php :

    $currentlang = get_bloginfo('language');
            switch ($currentlang) {
            case "nl-NL":
            $lang = "/nl";
            break;
            case "fr-FR":
            $lang = '/fr';
            break;
            case "en-GB":
            $lang = '/en';
            break;
            default: $lang = '/en';
    };

    if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) {
        $api_request_url = trailingslashit( home_url( $lang . '/index.php/wc-api/' . $request, $scheme ) );
    } elseif ( get_option( 'permalink_structure' ) ) {
        $api_request_url = trailingslashit( home_url( $lang . '/wc-api/' . $request, $scheme ) );
    } else {
        $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) );
    }

    return esc_url_raw( $api_request_url );
}

UPDATE

Woocommerce has now provided a filter to solve this issue https://github.com/woothemes/woocommerce/commit/56d303f4d3139336d539514f9dc15efda0a0381c