• Clicknathan

    (@clicknathan)


    We’ve got a WP install at a different location than the public site’s URL.

    So it’s a setup like this:

    wordpress.ourwebsite.com <- this is where WordPress is
    ourwebsite.com/wordpress <- this is where it displays on the front end, though

    So product URLs are like this:
    ourwebsite.com/product/classic-mens-t/

    Which leaves me with this error in Console:

    404 Not Found: /product/classic-mens-t/?wc-ajax=get_refreshed_fragments

    And the checkout page, too, which prevents credit card forms from loading / checkout in general.

    /checkout/?wc-ajax=get_refreshed_fragments Failed to load resource: the server responded with a status of 404 (Not Found)
    
    /checkout/?wc-ajax=update_order_review Failed to load resource: the server responded with a status of 404 (Not Found)

    I’m trying to figure out how to make it look for /wordpress/checkout/?THE_ENDPOINTS

    Any ideas?

    https://ww.wp.xz.cn/plugins/woocommerce/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Claudio Sanches

    (@claudiosanches)

    If the front-end is on ourwebsite.com/wordpress… Should the product page be in ourwebsite.com/wordpress/product/classic-mens-t/ ?

    Thread Starter Clicknathan

    (@clicknathan)

    Yes Claudio, the product page would be at that URL. Sorry for the miscommunication in the original post.

    I need the endpoints to be at ourwebsite.com/camping/checkout/?wc-ajax=get_refreshed_fragments

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Endpoint URLs use the current URL. See https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-ajax.php#L35

    Sounds like your config is messed up if this is failing.

    Thread Starter Clicknathan

    (@clicknathan)

    But if you have WordPress setup to use a different URL than where WP is installed, it gets confused.

    I have nothing in wp-config.php that declares the URL, just the standard WP config file.

    Are you saying they should know the right URL, or they use the actual current URL?

    Because the current URL isn’t what I need, but the one where WP exists. That is, wordpress.ourwebsite.com (where the WP installation actually lives).

    Is there a way to filter that get_endpoint function?

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Look again at what we’re using there.

    https://developer.ww.wp.xz.cn/reference/functions/remove_query_arg/

    $query
    (bool|string) (Optional) When false uses the current URL.
    Default value: false

    So is this breaking? Thats a WP core function.

    Thread Starter Clicknathan

    (@clicknathan)

    Well no, I believe it is using the current URL, if by that they mean the exact URL in the address bar.

    But if your WP install is not in the same directory as the front end (ie, on Settings > General you have different values for WordPress Address (URL) & Site Address (URL)) then it breaks in this case because Woocommerce is looking for the Site Address, not the WordPress Address.

    If I change that Woocommerce core file to this:

    public static function get_endpoint( $request = '' ) {
         return esc_url_raw(add_query_arg( 'wc-ajax', $request, remove_query_arg( array( 'remove_item', 'add-to-cart', 'added-to-cart' ), home_url() ) ) );
    }

    I just added home_url() near the end.

    That removes the error, but doesn’t allow me to checkout.

    If I access the site directly at the WordPress Address (URL), though, I can check out just fine with no problems.

    Thread Starter Clicknathan

    (@clicknathan)

    Hey Mike, made some more progress. To summarize everything here:

    WP URL = WordPress Address URL in settings, example: wordpress.website.com
    Site URL = The front end URL where the site actually displays: website.com/wordpress

    If I open up /includes/class-wc-ajax.php in Woocommerce core and modify the following, it works on the Site URL (website.com/wordpress/cart/):

    public static function get_endpoint( $request = '' ) {
    		$the_home_url = get_home_url().'/';
    		return esc_url_raw( add_query_arg( 'wc-ajax', $request, remove_query_arg( array( 'remove_item', 'add-to-cart', 'added-to-cart' ), $the_home_url ) ) );
    	}

    But then it gets confused on the WP URL. That’s probably not an issue because no one should ever be going to the wordpress.website.com version of the site, but it’s still there.

    And I know I shouldn’t modify core and all, just putting this here as a reference to how this can perhaps be resolved. πŸ™‚

    Perhaps that could do something like if get_home_url() == get_site_url() { $this } else { $that };

    Plugin Contributor Mike Jolley

    (@mikejolley)

    You can do a test such as <?php var_dump( remove_query_arg( 'test', 'test ) ); ?> on your site. If the URL returned is wrong, it could be indicative of a WP core bug, since it should use the CURRENT URL. In your case, your checkout page. Endpoints are appended to the current URL, not site url or home url. Make sense?

    Thread Starter Clicknathan

    (@clicknathan)

    I’m not sure I’m doing it right, but adding your code (with the last ‘ appended to the second test) just gives me:

    string(4) “test”

    And I hadn’t noticed Claudio’s note before, but yeah, my checkout page should be at

    ourwebsite.com/wordpress/checkout

    The error in console is:

    /checkout/?wc-ajax=get_refreshed_fragments
    Failed to load resource: the server responded with a status of 404 (Not Found)

    So it’s not even at the correct /wordpress/checkout/

    And my fix mentioned above…though checkout goes through, it appears things aren’t showing up in Stripe (though I have to double confirm that as I don’t have access to the Stripe account).

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Just an idea, but I wonder if this would affect it at all if you added to header http://www.w3schools.com/tags/tag_base.asp

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Rewriting URLs for Endpoints?’ is closed to new replies.