I have been trying to figure out how to make my guest checkout-enabled website work but with no success so far. I have the following WooCommerce settings activated:
Enable guest checkout
Enable registration on "Checkout" page
Normally, users should be able to checkout without creating an account, but can, however, opt to create an account if they want to. But if I place a test order as guest and check the "Create account?" box + fill out username and password fields, none of the information provided for billing and shipping shows up on the Thank You page or in the WP dashboard. It's as if the "Create account?" box + username and password would be ignored.
I suspect it has something to do with me having changed the default position of the account registration fields. I have added them to the form-login.php file so it shows up in the same section as the login form. They were originally included in the form-billing.php field. Below please find these files:
form-billing.php
<?php
/**
* Checkout billing information form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-billing.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.1.2
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
/** #global WC_Checkout $checkout */
?>
<div id="woocommerce-billing-fields" class="woocommerce-billing-fields">
<h3 class="billing-fields-title">Billing Address</h3>
<?php
do_action('woocommerce_before_checkout_billing_form', $checkout);
?>
<?php
foreach ($checkout->checkout_fields['billing'] as $key => $field):
?>
<?php
woocommerce_form_field($key, $field, $checkout->get_value($key));
?>
<?php
endforeach;
?>
<?php
do_action('woocommerce_after_checkout_billing_form', $checkout);
?>
</div>
form-login.php:
<?php wc_print_notices(); ?>
<?php echo '<div class="panel-group" id="checkout-accordion">'; ?>
<?php
/**
* Checkout login form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.0.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
if (is_user_logged_in() || 'no' === get_option('woocommerce_enable_checkout_login_reminder')) {
return;
}
echo '<div class="panel panel-default checkout-panel" id="panel-login">
<div class="panel-heading checkout-heading" id="panel-login-heading" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-login">
<h4 class="panel-title checkout-acc-title"> <a class="accordion-checkout">Login/Register <i id="checkout-accordion-login" class="checkout-accordion-icon"></i></a> </h4>
</div>
<div id="collapse-login" class="panel-collapse details collapse in">
<div class="panel-body checkout-inside"><div class="checkout-left-login"><h3 class="login-option">Login</h3>';
$info_message = apply_filters('woocommerce_checkout_login_message', '<div class="already-registered">' . __('Already registered?', 'woocommerce') . '</div>');
wc_print_notice($info_message, 'notice');
?>
<?php
woocommerce_login_form(
array(
'redirect' => wc_get_page_permalink( 'checkout' ),
'hidden' => true,
)
);
echo '</div>';
?>
<?php
if (!is_user_logged_in() && $checkout->enable_signup):
?>
<?php
if ($checkout->enable_guest_checkout):
?>
<p class="form-row form-row-wide create-account">
<input class="input-checkbox" id="createaccount" <?php
checked((true === $checkout->get_value('createaccount') || (true === apply_filters('woocommerce_create_account_default_checked', false))), true);
?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php
_e('Create an account?', 'woocommerce');
?></label>
</p>
<?php
endif;
?>
<?php
do_action('woocommerce_before_checkout_registration_form', $checkout);
?>
<?php
if (!empty($checkout->checkout_fields['account'])):
?>
<div class="checkout-right-register">
<h3 class="login-option">Create an Account</h3>
<div class="create-account">
<?php
foreach ($checkout->checkout_fields['account'] as $key => $field):
?>
<?php
woocommerce_form_field($key, $field, $checkout->get_value($key));
?>
<?php
endforeach;
?>
<div class="clear"></div>
</div>
<?php
endif;
?>
<?php
do_action('woocommerce_after_checkout_registration_form', $checkout);
?>
<?php
endif;
?>
<button id="toggle-login" type="button" class="register-btn-checkout" data-toggle="collapse" onclick="setCookie('panel-billing')" data-parent="#checkout-accordion" href="#collapse-billing">Continue</button>
</div><div class="or-select-guest">OR</div><button id="toggle-login2" type="button" class="guest-btn-checkout" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-billing" onclick="setCookie('panel-billing')">Checkout as Guest</button>
<?php echo'</div></div></div>';
?>
As a side note: the whole checkout form will be an accordion, with sections for delivery + billing, delivery options, and payment.
Am I missing anything? I suspect the issue might be related to the Woocommerce actions, but I can't tell for sure.
Are you using Woocommerce Subscriptions by any chance? I ask because I just had a similar issue and finally realized that guest checkout was actually working for any product except subscription products. I happened to be testing the checkout page with a subscription product in my cart... Since purchasing a subscription product assigns a user role, having one in the cart will require an account at checkout.
This may not help your specific situation, but maybe it will help someone else looking for answers.
Related
Am using The7 Theme. Since I wanted to create a NEWS section to post latest news (apart from the Blog, which is separate), I used the Custom Post Type UI plugin to create a custom post type named news
I created a new file in my child theme, by copying the contents of the parent theme's archive.php file and named it as archive-news.php, with a minor modification:
<?php
/**
* Archive pages.
*
* #since 1.0.0
*
* #package The7\Templates
*/
defined( 'ABSPATH' ) || exit;
$config = presscore_config();
$config->set( 'template', 'archive' );
$config->set( 'layout', 'masonry' );
$config->set( 'template.layout.type', 'masonry' );
get_header();
?>
<!-- Content -->
<div id="content" class="content" role="main">
<div class="news_years text-center">
<?php for( $i = date('Y'); $i >= 2009; $i-- ) { ?>
<?php echo $i; ?>
<?php } ?>
</div>
<?php
//the_archive_description( '<div class="taxonomy-description">', '</div>' );
if ( have_posts() ) {
the7_archive_loop();
} else {
get_template_part( 'no-results', 'search' );
}
?>
</div><!-- #content -->
<?php do_action( 'presscore_after_content' ); ?>
<?php get_footer(); ?>
So the modification done was that I commented out the description that would be shown at the top of the page, and added year buttons.
After this, when the www.mysite.com/news was accessed, it pretty well loaded all my news items and when clicking an item, it loaded the detailed page as well. And the pagination also works very well, as it inherits the parents theme's template files.
The problem am facing is, I want to make it display year wise items also. Say for example, right now, when accessing the www.mysite.com/news url, it loads up all the News items with pagination. I want to filter it based on a particular year. That's why I included the additional FOR loop in the above code.
Upon searching, I found that the WP Query has date parameters that can be used which will resolve my issue.
But am not sure how to apply this as this archive page is already doing the fetching of posts. And also, how to pass the year in the URL as well. Any pointers would be highly appreciated.
If this is not the right forum to ask this question, please feel free to move this thread to the apt forum. Thank you.
I'm working on my comment-section.
I have a very basic custom Comment_Walker. But it doesn't show the "Awaiting Moderation" string after posting a comment.
Comments are posted successfully to the backend. I have ticked that comments have to be manually approved in the settings in the backend.
A comment shows in the comment section in the backend as "pending". But I won't get the message when posting the comment.
My Walker File (very basic reduced to demonstrate)
<?php
/** Custom Comment Walker Basic */
class Custom_Comment_Walker extends Walker_Comment {
protected function html5_comment( $comment, $depth, $args ) {
$tag = ( $args['style'] === 'div' ) ? 'div' : 'li';
?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'has-children col-12 p-0' : 'p-0 col-12 list-unstyled' ); ?>>
<div>
<?php echo get_comment_text(); ?>
<?php if ( '0' == $comment->comment_approved ) : ?>
Awaiting Moderation
<?php endif; ?>
</div>
<?php
}
}
Accessing it via:
<div class="comment-list">
<?php
wp_list_comments( array(
'walker' => new Custom_Comment_Walker()
) );
?>
</div>
I don't quite understand why the message wouldn't show up. Do I oversee something here? Using the latest WordPress 4.9.6 on a localhost. I did deactivate literally every plugin I've had active before posting here. I have also tested this with different accounts and roles.
Apparently the solution was to have the "Save my name, email, and website in this browser for the next time I comment." checkbox selected in order for the message to show up.
So you have to have the GDPR checkbox to be checked in order to have the comment and message appearing before approval.
Sorry for bothering.
I have a woocommerce store and want to show wocommerce error messages in specific place of my theme, for example under submit button.
I know wocommerce error messages come from here:
<ul class="woocommerce-error">
<?php foreach ( $messages as $message ) : ?>
<li><?php echo wp_kses_post( $message ); ?></li>
<?php endforeach; ?>
</ul>
But, when i put this code in my page (for example edit-my-address.php page), its giving error!
What is working or simple code for showing messages in woocommerce?
Thanks in advance.
you can use both methods here..
woocommerce_show_messages();
wc_print_notices();
You can also show woocommerce custom notices according to your condition like...
wc_add_notice( 'This is a Success notice', 'success' );
wc_add_notice( 'This is a Error notice', 'error' );
wc_add_notice( 'This is a \'Notice\' notice\'', 'notice' );
You can add this piece of code to functions.php of your child theme
add_shortcode('woocommerce_notices', function($attrs) {
if (wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode woocommerce">
<?php wc_print_notices(); ?>
</div>
<?php
}
});
And then use it as a shortcode [woocommerce_notices] in any desired post or page, or use <?php echo do_shortcode('[name_of_shortcode]'); ?> in a desired PHP template.
Tested and works. Good luck.
A bit late to the party but here is a solution.
Try to use the following piece of code (taken from the original file here: wp-content/plugins/woocommerce/templates/single-product.php)
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
Hope it helps
you missed to add this line of code:
<?php wc_print_notices(); ?>
Add this to your functions.php file inside your child theme (or main theme if there is no child).
add_shortcode('woocommerce_notices', function($attrs) {
if (function_exists('wc_notice_count') && wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode">
<?php wc_print_notices(); ?>
</div>
<script>
(function($) {
$(window).on("load", function(){
// You can execute some js here
});
})(jQuery);
</script>
<?php
// You can execute some php here
wc_clear_notices();
}
});
Then add a shortcode to your page as:
[woocommerce_notices]
The notices and the code will get executed wherever you paste the shortcode.
I am creating custom search feature in a theme. I have created a form on the homepage and with action set to a custom php search page. Form looks like this somewhat. I AM GETTING Class WP_Query not found Error. How to make it work?
The woo-search.php looks like this. I am using this as a template file. forms action attribute links to the page which has this template applied
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
* Template Name: Search Page
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
global $wp_query;
global $wpdb;
if (isset($_POST['submit'])) {
// echo "Submitted <br>";
$product_kinds = $_POST['product-kinds'];
echo $product_kinds;
$the_query = new WP_Query(array('category_name' => '2-wheeler-batteries'));
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}else{
echo "Get Away";
}
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
For demonstration purpose the query inside wp_query is static. I want to display the search result just like the shop page looks like, I mean with product image, then title, then price and add to cart button. With above code I will need to fetch all seperately and code it to look like the shop page. How do I fetch Woocommerce layout in this search results. What changes should I make in the while loop.
<?php
/**
* The Template for displaying products in a product category. Simply includes the archive template
*
* This template can be overridden by copying it to yourtheme/woocommerce/taxonomy-product_cat.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
wc_get_template( 'archive-category.php' );
i am developing a E-commerce website in that i want to show only subcategories with their image and name and then after clicking on the subcategory name it should visit to the subcategory products page without affecting the taxonomy-product_cat page what to do please anyone can help ?
it is my code - both taxonomy-product_cat.php and archive-category.php
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header(); ?>
<div class="container-fluid"><div class="row">
<div class="col-md-10 col-md-offset-2">
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_id = $term->term_id;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail); ?>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
<div class="hovereffect">
<?php echo '<img class="img-responsive" src="'.$image.'">'; ?>
<div class="overlay">
<h2><?php echo '' . $category_name . ''; ?></h2>
</div>
</div>
</div>
<?php }
?>
</div></div></div>
<?php get_footer(); ?>