I just installed Woocommerce plugin on my Wordpress site and create my own custom theme. My theme structure should be like this:
.
├── index.php
├── style.css
├── functions.php
Now, when I tried to access, /cart route, it still load blank page (which i presume my homepage), and I can't load Woocommerce template that resides in ~/wp-content/plugins/woocommerce/template/cart/. I've read the docs here, but it only explains about template overriding.
Now, how do I load ~/wp-content/plugins/woocommerce/template/cart/ template, when i access /cart route on my site ?
I also tried to change my cart page attribute template on dashboard->pages->cart, but i can only set it as default template with no other options.
What you have so far is the basic wp custom theme structure.
In order to add Woocommerce support to your theme add this function to your functions.php file
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
Then if you want to have a custom cart page for example and not the default Woocommerce cart layout you have to add a folder Woocommerce in your theme root folder and and as a subfolder the part you want to override form the Woocommerce plugin template file.
Wordpress custom theme structure with Woocommerce support:
.
├── index.php
├── style.css
├── functions.php
├── woocommerce
├── cart
├── cart.php
If you are looking to use the default WooCommerce cart page, you will have to add what is called a 'shortcode' into one of your pages. The Wordpress editor will do the rest to set up the page and its functionality.
For the cart page, all you have to do is add a this text somewhere on the page that you would like to act as the cart: [woocommerce_cart].
If you would also like to use a checkout page, the shortcode for that is [woocommerce_checkout].
If you do either of these, you will also want to change the WooCommerce plugin's default cart and checkout pages to your pages. This can be done in 'Dashboard > WooCommerce > Settings > Advanced' under the 'Page setup' header.
This page may be a helpful resource if you have continued interest in using WooCommerce shortcodes in your site: https://docs.woocommerce.com/document/woocommerce-shortcodes/.
Related
I am developing my WooCommerce theme (hereinafter referred to as WC).
WC does not see the single-product.php template, and load index.php instead. At the same time, on the catalog page, the custom archive-products.php is loaded.
Guys, neither custom nor original single-product.php is loaded. Tell me, please, what to do?
I did:
Create woocommerce directory in theme folder
Inside mytheme/woocommerce I placed custom archive-products.php and single-product.php
I added WC support in functions.php. I checked the support in the site admin panel - everything is ok.
Check the directory again and make sure the file name is correct. it must be archive-product.php Not archive-products.php.
It's better if you copy the plugin template file in your theme directory then modify it.
Example: To override the archive-product.php, copy: wp-content/plugins/woocommerce/templates/archive-product.php to wp-content/themes/yourtheme/woocommerce/archive-product.php
Reference: https://woocommerce.com/document/template-structure/#how-to-edit-files
The solution provided in the link below no longer works:
Using a custom single product template for a specific product category in Woocommerce
I have worked through the diagnositic steps adumbrated by LOIC.
I added a copy of the single-product.php file to the woocommerce folder in my child theme.
When I checked the Woo status page it confirms that that page is overwriting the woo template.
I created a new product and assigned it the category: Custom (with the slug: custom).
I placed the following code in my functions.php:
add_filter( 'template_include', 'custom_single_product_template_include', 50, 1 );
function custom_single_product_template_include( $template ) {
if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-custom.php';
}
return $template;
}
I edited out the hooks from a copy of the single-product.php and renamed it: single-product-custom.php and put it in the woocommerce folder in my child theme.
Cleared all site caching and my browser history.
However, the test product is still displaying the default single product page.
Where I am going wrong and where do I go from here?
Problem resolved. Note: if you are seeking to use this solution there a couple of posts here with conflicting information. The solution above does work. The file to be placed in your theme folder is single-product woo template (with your custom title) not the content-single-product template as suggested in some other posts on this subject.
Also take care to note Loic's advice: If you are using a child theme. You create a woocommerce folder in your CT and then place the copy file in there. Do not place it inside a templates subfolder (as is the case in the Woo Plugin file structure).
I’d like to edit the "checkout" default WooCommerce form (fields like : billing address, first name, second name...etc.), but woocommerce template file form-checkout.php is not present in Avada Theme; other template files in woocommerce/checkout folder does not contain code for checkout form generating.
Where can I find template or define new custom template for checkout form in Avada?
I think the exact file you may need to edit is form-billing.php which is under woocommerce folder,the relative path not the form-checkout.php :
..\wp-content\plugins\woocommerce\templates\checkout\form-billing.php
you could edit this file in your child-theme by following these steps:
https://www.dreamhost.com/wordpress/how-to-customize-woocommerce-child-theme/
I want to create a website using wordpress, but I want my website to have a customized home page, created by me, completely different from the theme of the site, and then link the wordpress pages directly from my page.
Is this possible? How can I achieve this?
Can I simply create the page, and link the other created with the wordpress panel, without breaking everything?
According to official WordPress codex:
If a visitor goes to your home page at http://example.com/blog/, the following happens:
WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy.
If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page.
If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page.
Therefore you just need to create a home.php template and place it with the other theme (which so ever theme you will use) templates and WordPress will automatically start using home.php template for the home page.
Just copy the default page.php template file and call it front-page.php. Change the configuration at the top of that file. Now create a new page called home.
Go to Administration > Settings > Reading panel and set a static front page.
For more help check this link on the Wordpress website:
https://codex.wordpress.org/Creating_a_Static_Front_Page
If you create HTML off your home page first than this is easy for you
First Create a file Like this "template-home.php" in your theme.
Now in "template-home.php" First you must write these lines at the top of the page
<?php
/* ==========
Template Name: Home
========== */
?>
After that add your header.php and footer.php like this:
<?php get_header(); ?>
// Your Content is here
<?php get_footer(); ?>
Now your Whole HTML is work between in Header and Footer
Then Go to your Admin Panel
Go to Pages > add new
and create a page named "Home"
NOTE: When you create a page Please Select a Template of Home and "Publish" it.
Then go to Settings > Reading and select "A static page (select below)" radio button, then a drop down is active and select your "Home" Page Then click on save changes.
I hope this will help you
You can create a front-page.php file in your active theme folder.
It can be use for both Your latest posts or a static page as you want.
Wordpress themes have standard file such as header.php, footer.php, index.php, functions.php, style.css, ...
How to add a php file to wordpress theme addition of standard files? for example I want add a news.php to display specific posts in it, please help me
Just add a new file (e.g. news.php), and put the template comment at the very beginning:
<?php
/*
Template Name: News Template
*/
Then, go to your Wordpress backend, create a new page, and select the template you created: