I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.
Related
I've got the hook set up for 'woocommerce_hidden_order_itemmeta' but it is not being triggered during a purchase. My code is below. Note, the code is simplified with the function simply logging a message so I can see if it is being triggered.
function filter_woocommerce_hidden_order_itemmeta( $array ) {
error_log("GOT TO filter_woocommerce_hidden_order_itemmeta()");
return $array;
}
add_filter( 'woocommerce_hidden_order_itemmeta', 'filter_woocommerce_hidden_order_itemmeta', 10, 1 );
I have configured many other WooCommerce hooks and they are being triggered correctly. Is there something special about 'woocommerce_hidden_order_itemmeta'? Does something have to be configured elsewhere before this hook is triggered?
Thanks in advance for any help!!
Cheers!!
I had this same problem recently. Still trying to figure out what's going on, but I can sure you that, if you put this code at functions.php of theme, there's a great chance to get this specific hook to work.
However, this problem affects not only woocommerce_hidden_order_itemmeta hooks, but other ones like woocommerce_after_order_itemmeta, and probably everything suffixed by _order_itemmeta (only a personal guess in this last part)
Obs: Before trying this workaround above, certify yourself that you're using this hook on Order Details Metabox. I think this is the only place where these hooks like *_order_itemmeta are supposed to get work, anyway.
I have been trying for a while now to remove the image link from a Woocommerce product. I tried snippets, css and plugins. But nothing seems to work, until I came across Vitaly Gritsienko's answer of Jul 5 2017.
Although the code he suggests (see below) for the functions.php file works, the hand icon is still visible. How can I remove the hand icon?
//Removes links
add_filter( 'woocommerce_product_is_visible','product_invisible');
function product_invisible(){
return false;
}
//Remove single page
add_filter( 'woocommerce_register_post_type_product','hide_product_page',12,1);
function hide_product_page($args){
$args["publicly_queryable"]=false;
$args["public"]=false;
return $args;
}
Actually, the simplest way is to edit the theme's woocommerce listing page to remove the link from the templating engine, although it's better to do it via a child theme so as not to interfere with the main theme's updates.
You can read more about child themes here: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/
To remove the breadcrumbs I have a solution using css which I have used but I want to remove that using hook instead of css.
.breadcrumbs {
display:none;
}
Please let me know the hook to remove the breadcrumbs from all pages.
Hook to remove breadcrumb is following. Add following code in your theme's functions.php file.
add_action( 'init', 'd_remove_breadcrumb');
function d_remove_breadcrumb() {
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10);
}
I found out that I could go into its header-page file and just remove/comment it out.
It already had a do_action there, and if I then used a remove_action in functions.php, it came out an error.
Thank you all for using some time to answer and try to help, which made me think in some other way than I usually do.
I fished around the internet for a solution to this, tried a plugin or two to remove the /category/ from wordpress url's.
While some of these plugins are good, the category link still display's /category/.
Also I've tried putting in ./ in the category base options in permalinks settings.
Does anyone know how I could do like a php search and replace or something like that?
A cleaner solution:
add_filter('user_trailingslashit', 'remcat_function');
function remcat_function($link) {
return str_replace("/category/", "/", $link);
}
add_action('init', 'remcat_flush_rules');
function remcat_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter('generate_rewrite_rules', 'remcat_rewrite');
function remcat_rewrite($wp_rewrite) {
$new_rules = array('(.+)/page/(.+)/?' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2));
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
Using WordPress 3.9.1 (latest version as of this post) I simply added a single line to my theme's functions.php...
$wp_rewrite->add_permastruct('category_base', '%category%');
Then I opened Settings > Permalinks and hit Save. This appears to flush the permalink cache and makes it work.
http://wordpress.org/extend/plugins/wp-no-category-base/ and it doesn't alter permalinks, so removing it reverts the structure with no problem. And you don't have to alter core files.
https://wordpress.org/plugins/no-category-base-wpml/ is a plugin that solves the problem and works with current versions of WordPress.
Learning php, figure as well as following tutorials doing some practical useful stuff is import. So a wordpress plugin....
Trying to remove the favorite actions box that you get in the wordpress admin header.
<?php
/*
Plugin Name: Hide Favorite Actions
Plugin URI: http://www.mysite.com
Description: Allows you to remove the Screen Options and Help tabs from view
Author: Tai Havard
Version: 1.0
Author URI:
*/
add_action('admin_menu','removeHelpAndScreenOptions');
function removeHelpAndScreenOptions()
{
remove_action('favorite_actions');
}
?>
Plugins activated, function runs, I'm just not sure how to get hold of the favorite_actions correctly and wether remove_action is the correct function for use with the favorite_actions hook.
Thanks
Here's how remove action works:
remove_action( 'hook_name', 'function_name' );
That says you want to remove the function function_name from the hook hook_name. I don't know what the hook and function are fore removing help and screen options, though. If I remember correctly, those tabs are hardcoded into the actual admin pages.
I used that code and got an error in a template.php (presumably expecting an array) The box disappears if you return with an empty element, something like this:
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
$actions = array(
'' => array(__(''), '')
);
return $actions;
}
I just deleted the strings, somebody could probably write a more elegant empty array.
In your plugin just add
function rb_ax() {
return;
}
add_filter( 'favorite_actions', 'rb_ax' );
And you're done.
this works for me, wp 3.0.5
/**
* Remove "Favorite actions" from Admin
*/
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
return array();
}
I put it in functions.php, but it would probably work fine as a plugin.
returning nothing (void?) works, but writes Warning: Invalid argument supplied for foreach()...