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

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

Related

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

Change Wordpress theme but keep all old articles on old theme

I don't know if this is possible but I hope it is.
I run a very large Wordpress site with over 20 000 articles and I need to do a redesign now. However I'm trying to cheat by keeping all the existing articles in the same theme we are in now and only changing the new articles and the front page.
This is because a lot of the articles have custom page themes and embedded features that require the old functions.
So the question is, can I do this. is it even possble?
Or can I create static HTML files for every current article so when someone views it they get the old HTML instead of the new theme.
Also are there any terrible ideas here :)
I'd try adding a specific category to the old posts, say archives, and serving a different theme if the category or a single post in it is being viewed:
<?php
/**
* Plugin Name: Theme for Archived Posts
*/
add_action( 'setup_theme', 'setup_so_23040011' );
function setup_so_23040011()
{
add_filter( 'stylesheet', 'switch_so_23040011' );
add_filter( 'template', 'switch_so_23040011' );
}
function switch_so_23040011( $value )
{
if( is_category('archives') || in_category('archives') )
return 'twentytwelve'; // <-- The old theme
return $value;
}
To automate the assignment of the category to all 20k posts, another plugin with an on_activation procedure to iterate through them all and add the archives category. Something like this, but adapted to add the cat. Just activate and let it run, de-activate and delete afterwards (make sure to backup the db beforehand).

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' );
}

Roots Theme and WooCommerce - duplicated header

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.

Resources