Roots Theme and WooCommerce - duplicated header - wordpress

I installed WordPress 3.4.2 with the latest version of Roots theme (6.1.0 - October 2012), and the latest version of WooCommerce.
I found that the header method of Roots had a conflict with WooCommerce, which was also spitting out a default WordPress header. I ended up with two headers - one being the one I wanted (from Roots - the fixed Bootstap top navbar) and another which I didn't - my site name and the old "Just another WordPress website" subtitle.
How does one fix this?

This is because of the new version of Roots uses a "theme wrapper" which isn't compatible with the way Woo Commerce is looking for template overrides.
After a bit of head-bashing, I realised the simplest solution is just to do the following - in your theme folder, add a new header.php file, completely blank. That overrides the WooCommerce insert of your normal header.php file, then Roots can do its thing and pull out templates/head.php as your header.
You also need to add a blank footer.php
There is probably a more elegant solution removing hooks to the head and footer, but for now, that is a quick fix that is working for me. Once I've found the other method, I'll post it here.

I just tried this on Roots v 6.3.0 and ran into some issues. I used https://github.com/DoersGuild/wp-roots-woocommerce and then added the following block of code to the template file page-header.php located at in the templates folder in the root of the roots theme.
<?php if ( is_shop() ) {
/** If the shop page, do not display page-title **/
} elseif ( is_product() ) {
/** If a product page, do not display page-title **/
} else {
/** If is any other page, display page-title **/
the_title( '<h1 class="page-title">', '</h1>' );
}
I hope this helps someone.

Related

Woocommerce+Wordpress: Remove "Category:" text from title of each category page

I've been scouring the net trying to find the solution for this problem, despite it appearing to be quite simple.
I'm, as the title suggests, trying to remove the "Category:" from the title of each category page, while keeping the actual category text there, e.g. "Category: Footwear" should read "Footwear".
Now I have tried several of the solutions on this site but to no avail. The text still appears as it always has. I am using the Astra theme on WordPress.
I'm currently using the below code, but it doesn't work, hence my asking for help.
add_filter( 'get_the_archive_title', 'so_remove_category_prefix' );
function so_remove_category_prefix( $title )
{
if ( is_product_category() )
{
$title = single_term_title( '', false );
}
return $title;
}
If anyone has any solutions, I'd appreciate the help.
Thanks!
you can overwrite the woocommerce default template in your child theme and change content or title as per your requirement
default template file is located in below folder
wp-content/plugins/woocommerce/templates
You need to create a folder named woocommerce in your theme directory. After creating folder copy the template file folder to woocommerce folder in which you are created in your theme folder

How to show WooCommerce Categories on 'shop' page instead of products?

I have seen this question and answer. That does not work.
Setup
I am running:
WordPress 5.4.1
WooCommerce 4.1.1
I have a custom theme that overrides some of the WooCommerce templates by placing my own templates in: themes/my_theme/woocommerce/template-name.php
I have established that the shop page (homepage) uses the template archive-product.php. I have copied the this from plugins/woocommerce/templates/archive-product.php into my theme and made some minor HTML changes which work perfectly. There are no functional changes in my theme's copy, just some HTML.
The problem
I want the homepage to only show the store categories, as thumbnails. There is an option to set the shop page to show categories instead of products:
Appearance > Customize > WooCommerce > Catalogue
Shop page display has been set to Show Categories
However the shop homepage seems to ignore this setting entirely, and it still shows the products. It seems surprising that WooCommerce's own template does not honour this setting!
How do I find this setting in the template and then show the categories (as thumbnails) on the shop homepage?
Is there an equivalent to woocommerce_product_loop() for looping categories?
As a side note, the Storefront theme does honour the setting but Storefront does not have the template archive-product.php. Storefront seems to be highly abstracted and after much debugging of it / trying to take it apart I have so far not worked out which template file it is using for the shop page.
My theme is already in production and I just want to make an update so that the homepage shows the categories instead of going directly into the products list.
I found a workable solution. The WooCommerce default templates don't support the setting to show categories on the Shop page.
However using a shortcode with do_shortcode(), and a condition this can be achieved as follows:
if (is_shop()) {
echo do_shortcode('[product_categories hide_empty="0"]');
} else {
woocommerce_product_loop_start();
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
}
woocommerce_product_loop_end();
}
Still:
I would like to know how to pick up the 'show categories' customisation setting shown in the question, so my theme responds to that.
Is there a better way than using do_shortcode(), this feels like a bit of a hack

How to rewrite custom title and description only for blog in WordPress using child theme functions.php

How can I rewrite meta title and description in Wordpress using child theme functions.php?
I want to rewrite it only on main blog page (for example: www.example.com/blog), where I have listed all articles.
The problem is that the main theme already adds title and description to blog page. So I need to remove them first and then add custom ones.
Thank you very much for your help.
First off, WordPress does not add a <meta name=decription> tag. That is usually done by a seo plugin like Yoast, therefor the method for overriding it differ per plugin. Or theme.
You might be a able to change these texts in the wp-admin settings, again depending on the plugin/theme.
The title you should be able to change using this example:
function SO_52811727_wp_title($title) {
// see https://codex.wordpress.org/Conditional_Tags for more options
if ( is_archive() ){
$title = 'custom title';
}
return $title;
}
add_filter('wp_title', 'SO_52811727_wp_title', 100);

Custom Single Product Page Template Solution for Woo No Longer Works

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).

Changes on archive-product.php doesn't work

I'm trying to customize the standard woocommerce theme and so far that has worked well. I copied all template files from /plugins/woocommerce/templates to /mytheme/woocommerce and customized the files.
But when i'm change something in archive-product.php nothing happens? I even tried to customize this in the core files (/plugins/woocommerce/templates/archive-product.php) but i doesn't work.
I want to change the class of the h1 heading: <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>.
So i looked up all woocommerce template files, the class page-title occurs only in this one file (to prevent editing the wrong file).
Edit:
In detail, i want to customize the theme used in this path: http://example.com/product-category/mycategory
I tried all the above solutions, to no avail. No matter what I did, the archive-product.php was not being used at all. Instead, most woocommerce pages were using page.php from my theme.
The solution for me was to add theme support... Which, it's been a while since I used woocommerce, so I completely forgot about that. But after adding the following line to my functions.php file, archive-product.php is now being used (/mytheme/woocommerce/archive-product.php) and I can update it, as I should be able to.
add_theme_support('woocommerce');
Seems this is STILL an issue in Woocommerce. For anyone landing here, the following solution was working for me as of version 2.1.6.
Apparently the problem is due to the function woocommerce_content() outputting the wrong page for archive content.
I used the following to get around it:
replace woocommerce_content() in woocommerce.php with:
if ( is_singular( 'product' ) ) {
woocommerce_content();
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
woocommerce_get_template( 'archive-product.php' );
}
Credit: found the solution here
Here's how I fixed mine:
Delete woocommerce.php in your theme folder.
Copy TEMPLATE folder in woocommerce plugin dir, paste it in your THEME folder, and rename it to woocommerce.
Open the folder you just renamed, go to shop folder, and edit wrapper-start.php and wrapper-end.php.
If you use the woocommerce.php method you cannot customize archive-product. You must use the hooks method
http://docs.woothemes.com/document/third-party-custom-theme-compatibility/
Please note: when creating woocommerce.php in your theme’s folder, you won’t be able to override the woocommerce/archive-product.php custom template as woocommerce.php has the priority over archive-product.php. This is intended to prevent display issues.
For others searching here, doublecheck the path. It is for example not /mytheme/woocommerce/templates/archive-product.php but only /mytheme/woocommerce/archive-product.php. I didn't have to apply #Talk nerdy to me's patch or any other to make it work.
you need to edit the file "taxonomy-product_cat.php" and add a conditional is_product_category( 'mycategory' ).
open your theme folder and add a new subfolder named "woocommerce" to it.
copy the files "archive-product.php" and "taxonomy-product_cat.php" from /plugins/woocommerce/templates to the woocommerce subfolder in your theme.
rename "archive-product.php" to "archive-mycategory.php" (or whatever you like, this will be the template file to the category).
open "taxonomy-product_cat.php" and wrap the wc_get_template( 'archive-product.php' ); with:
if (is_product_category( 'mycategory' )){
wc_get_template( 'archive-mycategory.php' );
} else {
wc_get_template( 'archive-product.php' );
}

Resources