Woocoomerce remove product count from attributes - wordpress

On a WordPress installation with Woocommerce I have an issue with wrong number of product count on the frontend. That's why I decided to remove it. I have remove it from sidebars and anywhere with snippets but not on product attributes.
Is there any snipped to fix that?

If you want really remove (not just hide) you need to edit your theme function.php file by adding at the end this code:
add_filter( 'woocommerce_layered_nav_count', '__return_false' );
It's work for WOOCommerce v 3.4.3

Here is a quick snippet to remove products count after categories names using WooCommerce. It’s pretty useful in particular when your main shop page list categories instead of listing products. you can put it in 'functions.php' file in your theme.
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' );
function woo_remove_category_products_count() {
return;
}

Adding
small.count
{
display: none !important;
}
to your style sheet should work. It should hide the product count.

i think i allready have that.
See what functions.php file includes
<?php
define('ETHEME_DOMAIN', 'legenda');
require_once( get_template_directory() . '/framework/init.php' );
add_filter( 'woocommerce_subcategory_count_html', 'jk_hide_category_count' );
function jk_hide_category_count() {
// No count
}
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' );
function woo_remove_category_products_count() {
return;
}
you can swee live that is not worked at http://www.karadimos.gr/product-category/xalia/
BTW thanx for your reply!!!

Related

Show content before main content based on color attribute

I found a code snippet to display the content before the main content and it worked.
Currently the content is displayed on all pages. (except shop page)
The code :
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
if(!is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
What I want to ask is, how to display content only for color attribute products in the form of links.
Example :
The display (content) will ONLY SHOW when the url is like this :
mysite.com/color/red/
Sorry if the explanation is not good because I don't really understand this.
Any help is greatly appreciated.
thank you
I understand your question is about displaying that extra content, if the current query is for a product archive page only showing products of a certain attribute 'color'.
Each WooCommerce attribute is an independent taxonomy.
WordPress's is_tax('parameter') function checks, if the query is for an existing custom taxonomy archive page (other than category & tag) & if the query is for that specific taxonomy 'parameter', in your case 'color'.
So, this code snippet in your functions.php or equivalent plugin should work:
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
(is_tax('color')) {
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
Though, to make the above template WooCommerce override work, declare WooCommerce support for your theme by adding the following lines to your functions.php or plugin equivalent:
function theme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'theme_add_woocommerce_support' );

how to remove "added-to-cart notice" from every page except product archive pages?

Note: In looking for an answer to my question I came across this post but it is NOT duplicate: Remove add to cart notice and change "add to cart" button in Woocommerce the answer there gives the option to remove the notice from the entire site. I want to remove it only from the cart page and I don't want to do it with CSS.
I use external links to my site to send people directly to the shopping cart with the item already added to the cart. When doing so, the "added-to-cart notification" shows up on the cart page which I do not want.
I found this code which removes the added-to-cart notification: add_filter( 'wc_add_to_cart_message_html', '__return_false' ); but it removes the notification from all pages of my site which is not what I want.
To be more specific, I want the added-to-cart notification to show on every product archive page and nowhere else.
I tried to add a filter but it doesn't work the way I would expect it to, I tried the following two ways (and tested it with various pages to see if I could make anything work but it seems my general syntax is off because I Can't get it to do anything...
function hide_cart_notes() {
if ( ! is_archive() ) {
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
}
add_action( 'woocommerce', 'hide_cart_notes' );
function hide_cart_notes() {
if ( is_archive() ) {
return;
}
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
add_action( 'woocommerce', 'hide_cart_notes' );
when woocommerce hook starts? where it's docs? does it run at all?
these question should be answered before.
i know that WordPress parses query at parse_query hook, so i would try this
add_action('parse_query', function() {
if (!is_archive()) {
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
});
because is_shop(), is_archive(), is_* need query to be parsed first.

WooCommerce - How to remove sidebar

I need to remove sidebar into my woocommerce store.
I have tried with backend in option theme and in each category but resultless.
I tried also:
1.file wp-template-hooks.php
removed--> do_action(..
2.file archive-product.php
removed--> do_action(..
insert in file function.php in theme dir and function.php in woocommerce dir
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
into database there is 2 tables with 2 fields serialised but is a risk change this.
resulless.
I finished the ideas.
Where is saved into db the visibility of sidebar? or the variable?
Can you help me?
Thanks
Ale
I just wanted to update this post for WooCommerce version 3.2.3 - 2017
OK the WooCommerce Plugin includes a folder with all the template files if you want to make changes to the template on a custom theme or child theme you need to copy all of the desired template into a folder called woocommerce in your root theme folder. This will overwrite the plugin templates and will allow for WooCommerce updates with overwriting your custom changes. These templates have all of the do_actions and hooks in the comments so it makes it easy to understand how it's working.
That said WooCommerce has hooks that allow for you to add or remove blocks of code you can check out the API Docs here.
To remove the side bar you need to add this into your functions.php file in your theme setup function
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
Please, add this code to your functions.php
function mb_remove_sidebar() {
return false;
}
add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );
Add to functions.php the following line:
add_action( 'init', function () {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
} );
You have already integrated WooCommerce in your theme?
If not, try to do this three steps for integration WooCommerce in your theme.
After that, remove get_sidebar(); from your_theme/woocommerce.php
It works fine for me. Screenshot here.
Hope it helps.
Further to #maksim-borodov's answer, I wanted to hide the sidebar conditionally, i.e. only on Product pages. Here's how:
function remove_wc_sidebar_conditional( $array ) {
// Hide sidebar on product pages by returning false
if ( is_product() )
return false;
// Otherwise, return the original array parameter to keep the sidebar
return $array;
}
add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );
Add to functions.php the following line:
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
I am using GeneratePress (free version), so the other solutions didn't work for me.
This page gave me the answer: https://docs.generatepress.com/article/sidebar-layout/#sidebar-filter
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a woocommerce page, set the sidebar
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
This can be done by woocommerce sidebar plugin. If you want to remove by code add this code to functions.php,
if (!class_exists( 'WooCommerce' ) ) {return;}
if(is_cart() || is_checkout() || is_product() || is_shop() || is_account_page()){
?>
<style type="text/css">
#secondary {
display: none;
}
#primary {
width:100%;
}
</style>
<?php
}
}
Here is how to remove the sidebar :-
go to wp-content/plugins/woocommerce
in file single-product.php remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
next edit the file archive-product.php and remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
(tip* before deleting this, copy and paste the entire code from this page into a seperate text file on your HD...that way you can always paste the original code back into this folder if anything goes wrong)

Searchform not showing up

I have made a custom searchform.php to go with a Genesis child theme! However my custom form is being replaced by the Genesis Default Searchform.
In the child theme's functions.php page I have added this snippet....
function search_form_no_filters(){
// look for local searchform template
$search_form_template = locate_template( 'searchform.php' );
if ( '' !== $search_form_template ){
// searchform.php exists, remove all filters
remove_all_filters('get_search_form');
}
}
add_filter( 'get_search_form', 'genesis_search_form' );
This naturally should pull up my custom form and replace the Default Gensis one but for some reson it's not!
Have I missed something out here?
Many thanks.
I think add_filter part is the reason for the form not being displayed.
use add_filter( 'get_search_form', 'search_form_no_filters' );

Remove the Product Count on Woocommerce Categories

pic http://goo.gl/hnRfG9
I want to hide product count form category : I tried this in functions.php of theme
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' );
function woo_remove_category_products_count() {
return;
}
But it does not work. I edit this from theme editor and also from directory to make sure its written.
That one works for me:
add_filter( 'woocommerce_subcategory_count_html', 'jk_hide_category_count' );
function jk_hide_category_count() {
// No count
}
Picked it up in WooC tuts somewhere.
Try this one:
/** Remove Showing results functionality site-wide */
function woocommerce_result_count() {
return;
}

Resources