Endpoints not working on WooCommerce checkout page - wordpress

I developing a custom theme. I have an issue on checkout page. When I click on 'Place order' button the URL of checkout page changing from http://localhost/sitename/checkout to look like http://localhost/sitename/checkout/order-received/390/?key=wc_order_DvIkeeaIUoNFI if payment-method is 'Cash on delivery' or http://localhost/sitename/checkout/order-pay/391/?key=wc_order_2TbWibkoOZcxz&order=391 if I choose Internet acquiring payment-method.
But on that pages displayed content of checkout page. I think that endpoints don't work.
Here is what I did to fix that issue:
Checked endpoints in WooCommerce -> Settings -> Advanced
Created new checkout page and deleted old
Checked Chrome DevTools Console for JS errors
Turned off all plugins except for WooCommerce. Issue still exists.
Checked it on another test-site with Storefront theme. Everything works.
Checked all default Woocommerce hooks in my custom checkout templates. There are available.
Create web.configfile in site's directory with code which provides on https://woocommerce.com/document/woocommerce-endpoints-2-1/
Trying to redirect with this code:
<?php
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( home_url('/thank-you') );
exit;
}
if ( is_checkout() && !empty( $wp->query_vars['order-pay'] ) ) {
wp_redirect( 'https://secure.wayforpay.com/pay' );
exit;
}
}
?>
As for me it's bad solution. Because if payment-method is 'Cash on delivery' on thank you page it is not possible to get order data, and if method is 'Internet acquiring' I need to get and transfer order data to acquiring system, but I have a plugin which should do it without my participation. And plugin working on another test-site.
This issue is very popular among junior Wordpress-developers, but there is few information about solving this problem.
I think that endpoints works incorrect, but I don't know how to fix it.
I will be very grateful if you share your own experience in solving the problem or tell me what to look for.
Updated
In addition I compared requests and responds in Chrome->DevTools->Network between site with Storefront theme and my site. They are the same, but on my site the redirect is not happening.

I fixed it.
Main issue consist in that my woocommerce doesn't do shortcodes from Console->Pages, so I activated checkout template via page-checkout.php where I get template part form-checkout.php (get_template_part( 'woocommerce/checkout/form-checkout' );).
To fix a bug I replaced this string with echo do_shortcode(['woocommerce_checkout']);.
Very simple solution that I spent almost 3 days searching for, but even better I learned how wordpress works

Related

Change the default global edit link that lists my CustomPostType (edit.php?post_type=CPT), to use a plugin page link instead

I'm working on a plugin (with a https://wppb.me/ plugin boilerplate base, if relevant).
I defined my custom post type, with the editor options I want, that I can edit with the default /wp-admin/post.php?post={id}&action=edit
The listing of those CPT is done on my plugin pages only (no specific menu for the CPT) and I want to keep it that way.
Problem:
I'd like to change the base edit link of this post type when no ID is specified
( eg : /wp-admin/edit.php?post_type=CPT ) to be the URL of my plugin
( eg : /wp-admin/admin.php?page=myplugin )
This, mostly because in Gutenberg Editor Fullscreen, the top left wordpress logo links to the /wp-admin/edit.php?post_type=CPT that I don't wont to use nor show. I'd like this link to be a page of my plugin (here, it would be the homepage of my plugin)
I tried with a filter on get_edit_post_link when there is no ID provided, but it doesn't seem to be the correct way to fix my problem.
Any tips or help to get me in the right direction in my research are welcome !
I found one of the possible solutions. After entering the site, you must redirect the user.
function wp_custom_update_meta_cache_filter() {
global $pagenow, $typenow;
if ( $pagenow == 'edit.php' && $typenow == 'CPT' ) {
wp_safe_redirect();
die();
}
}
add_action( 'admin_init', 'wp_custom_update_meta_cache_filter' );
Based in (233 line):
https://github.com/dipolukarov/wordpress/blob/master/wp-content/plugins/woocommerce/admin/woocommerce-admin-init.php

Why are my Woocommerce permalinks conflicting with main website pages?

Was wondering if someone could point me in the right direction.
My current Woocommerce Permalink settings are as follows:
SHOP
www.mywebsite.com/shop
SHOP WITH SUB CATEGORY
www.mywebsite.com/seasons/winter
Unfortunately, the above SHOP WITH SUB CATEGORY link also works without the product category - i.e. www.mywebsite.com/winter - for some reason.
Which is annoying as I also have a main page in my website called Winter. (i.e. mywebsite.com/winter).
I have tried various versions of the COMMON, OPTIONAL and PRODUCT permalinks, but no matter what I type, www.mywebsite.com/winter always points to the Woocommerce Shop page and not the normal website page.
Any ideas?
Huge thank you in advance :)
Steven
What happens when you use this? This code stops WordPress from guessing where to go.
function no_redirect_guess_404_permalink( $header ){
global $wp_query;
if( is_404() )
unset( $wp_query->query_vars['name'] );
return $header;
}
add_filter( 'status_header', 'no_redirect_guess_404_permalink' );
Original answer

How to add #anchor at the end of the Wordpress URL if the traffic source is coming from Google search

I have Wordpress and I would like that all visitors who access my site by searching in google (traffic source), go directly to a specific part of the page (focus).
To focus on this part, I need to include the anchor at the end of the url: #welcome-source-google
https://example.com/category/page-or-post/#welcome-source-google
I think I need to insert this code, probably in functions.php:
function organic_source_anchor() {
if (preg_match('/(www\\.)?google\\./', $_SERVER['HTTP_REFERER'])) {
wp_redirect( get_permalink( $postID ) . '#welcome-source-google' );
exit;
}
add_action( 'template_redirect', 'organic_source_anchor' );
I got this code by researching, but since I am not a programmer, I believe there are several errors or maybe I need to put the code out of functions.
A problem that happens is that I didn’t want to disable the cache, as this frame appears to all visitors, but if the source is from google, I wanted the focus on the part this page.

Seo yoast plugin, breadcrumbs

This is question on the seo yoast wordporess plugin.
I have a friend who doesn't know that much about code/wordpress/etc, they have an ecommerce site built using magento and a blog using wordpress which is styled to match the main site and they use yoast seo plugin for seo etc. They have asked me to try an get the breadcrumbs working for them in a different way to what i know, from what i can see they want to add a prefix to the breadcrumbs 'home' which links to main site then renaming the blog from home to blog, for example home(main site) > blog(blog) > post.
Now i did just that in the plugin settings but they said that the schema markup wouldn't be complete and said there’s a filter hook called ‘wpseo_breadcrumb_links’ which gives access to the array of URLs and anchor text used to build the breadcrumbs, now i cant find anything on google that explains this or how to start writing it, i do know that it needs to go in the functions file.
Would it be possible to get some help on this.
Thanks in advance and very much appreciated.
Justin
I'm not sure what Schema.org markup has to do with breadcrumbs! :) Schema is used on post/page level. So, they are either oversmarting themselves or I got you wrong.
I think this sample code may be helpful:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = '<span typeof="v:Breadcrumb">Products</span> »';
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
It looks like wpseo_breadcrumb_output gives you access to the entire output instead of just the link portion. Please see this page for more details: http://wpquestions.com/question/showChrono/id/8603

Disqus and WooCommerce review compatibility issue

I am trying to use Woocommerce plugin and Disqus plugin together on my WordPress blog.
As I can see from other posts on internet, lot of users such as me are facing the issue that - Disqus disables reviews on product page created by Woocommerce.
As Disqus disables WordPress comments which in turn are used by Woocommerce for product review - now there is no way (as far as I could know) to show review form on Woocommerce.
Can anyone suggest a fix for this?
I have already tried the following:
Open Disqus plugin directly.
Go to line number 150 in disqus.php
notice the conditions which says for which posts types Disqus should not render comments.
add - if ( is_product() ) { return false; }
This will stop showing Disqus comment box from product pages created by Woocommerce and it will show usual review form. However, on submitting this - you will receive an error saying WP comments have been disabled.
Can anyone help me here?
I solved this by adding this code to my functions.php file:
add_action('the_post', 'sb_remove_woocommerce_disqus', 10, 2 );
remove_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
function sb_remove_woocommerce_disqus( $post, $query ) {
global $post, $wp_query;
if ($query->is_main_query() && $post->post_type == 'product') {
remove_filter('comments_template', 'dsq_comments_template');
}
}
My problem was if I used Disqus plugin, it replaced my WordPress comment system with Disqus. Thus, disabling reviews on Woocommerce pages.
So instead using Disqus plugin, I simply used its universal code and added to my single.php file, before <?php comments_template(); ?> to be precise.
This seems to work.

Resources