I have a developed an e-commerce website with WordPress and WooCommerce plugin. Everything has been done but I want to change the complete layout of the checkout page. I tried finding a plugin to do that but failed.
Is there any way by which I can change the layout or the design of the checkout page?
EDITED:
THE WOOCOMMERCE TEMPLATES:
You can copy the "templates" folder (located inside the woocoommerce plugin folder) to your theme (or child theme) folder and rename it "woocommerce".
Then you can chose inside which file you want to edit to feet your needs.
In your case you will find inside a folder named "checkout". All the files inside this "checkout" folder are the different components of the checkout page layout.
Different files responsible for components on checkout page/form
form-checkout.php is the primary file called for checkout page.
form-login.php renders the login form.
form-coupon.php renders the coupon form.
form-billing.php renders the billing form.
form-shipping.php renders the shipping form. (this is displayed when "ship to different address checkbox is checked)
review-order.php renders the order review block.
payment.php renders payment options block.
payment.php has a loop in which for each enabled payment method another file > payment-method.php is called.
cart-errors.php displays cart error.
thankyou.php is called for displaying order received confirmation. ("order-received" endpoint)
ADDING WOOCOMMERCE STYLE SHEET IN CHILD THEME FOR EASY MODIFICATION
Because some times is very difficult to overrides some specific WooCommerce styles.
Step.1 - Disable the general woocommerce.css file.
Add this PHP code to your active theme's functions file (functions.php):
add_filter( 'woocommerce_enqueue_styles', 'wooc_dequeue_styles' );
function wooc_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] );
return $enqueue_styles;
}
Step.2 - Create a new folder inside your active theme's folder named "woocommerce" (if it doesn't exist yet).
Step.3 - Copy the woocommerce.css file into this newly created folder woocommerce in your active theme's folder.
The woocommerce.css file is located in: plugins/woocommerce/assets/css/woocommerce.css.
Step.4 - Enable (enqueue) the general woocommerce.css file in your active theme.
Add this PHP code to your active theme's functions file:
add_action('wp_enqueue_scripts', 'woocommerce_style_sheet');
function woocommerce_style_sheet() {
wp_enqueue_style( 'woocommerce', get_stylesheet_directory_uri() . '/woocommerce/woocommerce.css' );
}
Options:
— You can also enable/disable others woocommerce css files: see this snippet at woo themes
— You can disable ALL Woocommerce style sheets at once:
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
Related
I am creating a custom theme and I have copied the file content-product.php to my theme folder. There I have made changes to the html structure and css. I can load of list of products and see the changes working via the short code [products].
However elsewhere on the site I want to display another list of products but from a different category. I would use the shortcode [products category="special category"] These products should be displayed using a different template.
My question is: Where can I inspect the shortcode query? and how can I conditionally load a different template depending on which products are being displayed?
In my themes functions.php file I have started to extend the [products] shortcode like this:
function my_wc_shortcode_product_query_args($args, $atts){
if ( isset( $args['category'] ) && $args['category'] == "Daoine Óga") {
var_dump($args);
// Tell Woocommerce to load my custom template instead of the my-theme/woocommerce/content-product.php
}
return $args;
}
But I'm not sure how I can return or get woocommerce to display my custom template at this point.
The woocommerce file that creates the [products] shortcode can be found at plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
Make a folder in plugins folder called custom-product-templates and make a copy of the woocommerce file class-wc-shortcode-products.php to that folder.
Add the plugin comments to the top of that file:
/*
Plugin name: Custom Product Template
Plugin URI: https://anirishwebdesigner.com
Description: Display custom product templates in woocommerce loop
Author: Linda Keating
Author URI: http://anirishwebdesigner.com
Version: 1.0
*/
Navigate to localhost/wp-admin in browser and to the plugins and activate newly created plugin
I can now safely edit that file so that the shortcode behaviour loads the template I want based on certain criteria.
First extend the class so that it accepts a template attribute
In the parse attributes function add
'template' => '',
Then search for wc_get_template_part('content', 'product'); and modify the code here to load different templates in an if..else statement. Something like:
`if($this->attributes['template'] == 'Daoine Óga') {
wc_get_template_part( 'content', 'childrenproduct' );
} else {
wc_get_template_part( 'content', 'product' );
}`
If there are simpler / better solutions please let me know.
I am using a simple theme in WordPress, that pulls it's customizers sections from the plugin ThemeHunk Customizer.
I want to hide certain sections in the customizer section, but when using $wp_customize, it isn't working.
This is what I am trying to hide:
$wp_customize->add_section('section_home_ordering', array(
'title' => __('Section Ordering', 'featuredlite'),
'priority' => 3,
));
This is located in the /wp-content/plugins/themehunk-customizer/featuredlite/customizer/customizer.php file.
I have added this to my functions.php file in my child theme directory:
function customize_register_init( $wp_customize ){
$wp_customize->remove_section('section_default_home');
$wp_customize->remove_section('pro_button');
$wp_customize->remove_section('Docs_button');
$wp_customize->remove_section('section_home_ordering'); - THIS IS THE SECTION I would like removed from the /plugin/ file
}
add_action( 'customize_register', 'customize_register_init', 99 );
It doesn't seem to remove though, like it would if you were removing a section from a parent theme.
Is there another method to do this, or is this not possible to remove from a plugin rather than a parent theme?
Thank you in advance.
SOLVED I use the customize_controls_enqueue_scripts hook to input custom CSS within the wordpress customizer, so I can display certain elements as hidden!
In theme your code works fine. Maybe it depends on action hooks order.
Have you tried?
add_action( 'plugins_loaded', 'customize_register_init', 99 );
You can simply go with these documentation as it shows you can disable particular section of Home Page (FrontPage). You can change order of appearance also from the Appearance > Frontpage Section > Section Ordering.
Reference Link: https://themehunk.com/docs/shopline-theme/#frontpage-section
https://themehunk.com/product/shopline-free-shopping-theme/
I am trying to use Woocommerce's wc_get_template function to load my own templates, but it dosen't seem to work (it's not outputting content from the template files), together with my Woocommerce plugin. Below is what I have tried:
plugindir/templates/testing-template.php:
<h1>Output stuff</h1>
plugindir/pluginname.php:
if(in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option('active_plugins')))) {
function template_loader(){
wc_get_template('testing-template.php', array());
}
add_action('init', 'template_loader');
}
wc_get_template will first try to load the template from the the theme in the woocommerce folder. If it does not find the template in the theme's woocommerce folder it will try and load the template from woocommerce templates folder.
wc_get_tempalte will not just work with any template you want. If you are building a plugin of your own you can try and look at the WC_Template Class and try to mitigate the functionality of wc_template in your own plugin with plugin_prefix_template() and also have a templates folder in your plugin.
https://docs.woocommerce.com/wc-apidocs/source-class-WC_Template_Loader.html#13-510
As I understand by default Woocommerce shop page uses product archive template. What I am looking for, is to use a custom template for shop page.
Here is what I did:
Create template "my-shop"
Create page "My shop" -> choose template "my-shop"
Choose "My shop" as Woocommerce shop page
But none of the changes I made to "my-shop" template are present on the shop page.
What am I missing here? I would not like to change product archive itself, just the shop page.
Is there a way to disable product archive from being a default for shop page?
Thanks
I know it's too late and you may have figured it out by now. In any case, the changes that you would like to make to the WooCommerce Shop Page need to be done in the archive-product.php and it would be safer to create a child theme and do these changes. Making enhancements and customizations in a Child theme is best practice so that you can update the parent theme at any time and it won't affect your store.
I hope this helps, for more information on how you can use WooCommerce short-codes to customize your store can be found here.
To add to Silver Ringvee's answer - he used is_page but that only works on wordpress pages. For woocommerce you need to use something like is_woocommerce() . See Woocommerce conditional tags page.
My example code uses the is_shop conditional tag as that was the page you wanted to change. the code get_template_part( 'content', 'shop' ); will call the file content-shop.php in your theme root folder. This code is to be added at the top of wp-content\themes\*theme*\woocommerce\archive-product.php that you can copy from wp-content\plugins\woocommerce\templates\archive-product.php
You can add it just before get_header( 'shop' ); line 23 in my file - and the entire page will be drawn from your template. If you want to keep the header of the shop page, then put this code after the get_header code. Remember to include a footer in your file as well
if (is_shop()) {
get_template_part( 'content', 'shop' );
} else {
#normal archive-product code here
}
The solution (not perfect) that I figured to work best, until someone finds a way to actually change the template from dashboard:
Adding:
<?php
if (is_page( 'Page Title' ) ):
# Do your stuff
endif;
?>
to content-product.php in my theme's woocommerce folder.
If you prefer to go with code, you can create a redirect from the original shop page to your page via wp_redirect.
add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages()
{
if (is_shop())
{
wp_redirect('your_shop_url_here');
exit;
}
}
More detailed tutorial can be found here
This is not possible to create custom template for shop page , just copy and paste woocommerce Templates into you theme folder and Try to work in content-product.php template .
I can't work on any specific theme file like header.php, footer.php OR function.php within theme directory.
Reason is project always need new theme and theme is get changes in each week.
So I want something like that will work on each theme, no matter which theme admin applied.
I tried wp_enqueue_script() but again I need work on theme's function.php file.
The only way to do this is to run wp_enqueue_script() from outside of the theme (i.e. NOT in functions.php). The only way you can do that is to use a plugin.
See: http://codex.wordpress.org/Must_Use_Plugins
Or: http://codex.wordpress.org/Writing_a_Plugin
Create a plugin by adding a .php file in the /wp-content/plugins/ directory, or possibly even better for this situation create a 'must use' plugin by creating a .php file in the /wp-content/mu-plugins/ directory.
The structure of this .php file should be something like the following:
<?php
/*
Plugin Name: Example Plugin
Description: Any functions that should persist even if the theme changes.
Author: Your Name
Version: 1.0
Author URI: http://yoururl.com
*/
function my_scripts() {
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}
add_action('wp_enqueue_scripts', 'my_scripts' );
?>
You need to write a plugin that rewrites theme's sections. A good start for creating a plugin is here. If your themes shares the same Javascript you could try to add your things to those Js.