Woocommerce thankyou page is not working after checkout - wordpress

Today I ran into an interesting issue. After payment thankyou page is not displayed. There is only white screen with menu. You can see it in the screenshot. thankyou page http://prntscr.com/ofpnuu
I tried to create a custom thankyou page and tried to redirect it from the function.php but nothing happened. Then I installed the plugin to create thankyou page but again nothing happened. I have run out of ideas. Can someone tell me how to solve this issue.

Use the hook below to redirect to the thank you page. Create a thank you page and redirect to that url...
Check the code below:
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'http://www.yoururl.com/your-page/' );
exit;
}
}

Related

Change 'home' link in breadcrumb to specific page

I'm using the Avada theme, and trying to edit the breadcrumb Home link. It has to refer to another link. The wordpress given code isn't working. Someone got any idea?
Using original given wordpress code isn't working. The exact URL isn't doing the job, nor is the return get_permalink( $shop_page_id ).
Code below isn't working:
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
$shop_page_id = get_option( 'woocommerce_shop_page_id' );
return get_permalink( $shop_page_id ) ;
}
Hope anyone can help me to get this done using the Avada theme?

How can I remove search result page

I made a new website, and I have a little problem. The site doesn't need any kind of search engine etc..
So I don't need the search result page.
Is there maybe a way to make searching and search page redirect to home page?
So basically I want to redirect any user trying to access this page https://example.com/?s= to home;
Thank you
You could add the code below into your themes functions.php
add_action( 'template_redirect', 'redirect_s_to_homepage' );
function redirect_s_to_homepage(){
if ( is_search() && ! empty ( $_GET['s'] ) ){
wp_safe_redirect( home_url(), 301 );
exit;
}
}
It makes sure your loading search page and that there is a search variable set, and redirects you.
EDIT
The code above will work when there is an actual search query. example: ?s=something.
Since you are also wanting to redirect if there is no query, try the snippet below.
add_action( 'template_redirect', 'redirect_s_to_homepage' );
function redirect_s_to_homepage(){
if ( is_search() && isset( $_GET['s'] ) ){
wp_safe_redirect( home_url(), 301 );
exit;
}
}
The first code was making sure ?s= wasn't empty. The edited code just makes sure ?s= is set.
We have an action hook called 'template_redirect' , for search query we can do following to achieve:
function wm_search_redirect(){
global $wp_query;
if( $wp_query->is_search) {
wp_redirect( home_url() );
die;
}
}
add_action( 'template_redirect', 'wm_search_redirect' );
Please test it on non live site, as it is untested code just for idea.

How to Stop Accessing WordPress Page When User Login

I am trying to stop users from accessing a page when they already login. Anyone please help me how to do this. I checked it on google and all over the stake overflow but did not find any solution. Hope to get answer soon.
Thanks
try this code bellow , put it within your theme function.
function my_page_template_redirect()
{
if( is_page( 'page-slug' ) && is_user_logged_in() )
{
wp_redirect( home_url() );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
Change page slug based on your case, you also can use page_id check these references bellow. Don't forget to save permalink after put that code
Reference :
https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
https://developer.wordpress.org/reference/functions/is_page/

Require WordPress Login only for posts, not pages?

I'm trying to create a WordPress site with a login system, but I only want the login to be required to view POSTS. They should be able to view pages without logging in. I did some research, but no one had exactly what I was looking for, so I tried to puzzle something together, and this is what I came up with, but it doesn't work.
function my_force_login() {
global $post;
if ( ( is_single() && !is_user_logged_in() ) ){
auth_redirect();
}
}
Any ideas?
add it to your single.php
<?php auth_redirect(); ?>
This function will check if the user is logged in and if he is not it will redirect him to the login page http://codex.wordpress.org/Function_Reference/auth_redirect
Your code works, but it has run on the correct point:
add_action( 'template_redirect', function()
{
global $post; // Use this to detect the custom post types if needed
if ( ( is_single() && !is_user_logged_in() ) )
{
auth_redirect();
}
});
Details of the post is being displayed in the single.php. Please put the code of displaying post's content into the condition. Then you will get the solution. Try the following code into the single.php in the twentyforteen theme.
if ( is_user_logged_in() ) {
get_template_part( 'content', 'single' );
}
Now get logged out and refresh the browser, you can see none of content are shown.

WooCommerce: Redirecting to cart page if thankyou page is requested without an order

If a user tries to directly access the 'Thank you' page they should be redirected to the woocommerce cart if there isn't an order in the request.
I've submitted a feature request for the above over on the Wordpress forums. In the meantime I was hoping somebody could think of a way of doing this via functions.php in my theme?
I'm unable to use the woocommerce_thankyou hook as this isn't loaded when you just land on the page (it's only hookable if you land on the thanks page with an order from the checkout).
Is there a way in functions.php I can check that it's the woocommerce thankyou page and also check if there's a global $order object?
add_action( 'template_redirect', 'your_template_direction_function' );
function your_template_direction_function() {
global $woocommerce;
if ($woocommerce && is_page( woocommerce_get_page_id( 'thanks' ) ) && sizeof($woocommerce->cart->get_cart())==0) :
wp_redirect(get_permalink(woocommerce_get_page_id('cart')));
exit;
endif;
}

Resources