I'm currently trying to remove all messages from the WooCommerce account with the following code line:
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );
Sadly, the wrapper for messages is still there:
<div class="woocommerce-notices-wrapper">lol</div>
I've added a lol to the function that displays the wrapper and it's the correct function I'm trying to remove. No idea why it's not working...
If your active theme uses the default woocommerce templates and hooks for myaccount pages, then add the follows code snippet to achieve the above -
function modify_wc_hooks() {
// remove all wc my account's notices wrapper
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
}
add_action( 'init', 'modify_wc_hooks', 99 );
Codes goes to your active theme's functions.php
Related
Up until a recent update (for Woocommerce, and also the Storefront theme), I was able to remove breadcrumbs using the following code in the child theme functions.php
add_action( 'init', 'z_remove_storefront_breadcrumb' );
function z_remove_storefront_breadcrumb() {
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10 );
That solution is described here.
Since the update (and I am not sure if it was the WC or SF update that did it) this no longer works.
I also tried the other method suggested in the above-mentioned post. And a few other methods, all listed here:
add_filter( ‘woocommerce_get_breadcrumb’, ‘__return_false’ );
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
and
add_action( 'init', 'jk_remove_storefront_breadcrumb' );
function jk_remove_storefront_breadcrumb() {
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10 );
}
also
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
also
add_filter( ‘woocommerce_get_breadcrumb’, ‘__return_false’ );
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
also
add_filter( 'woocommerce_before_main_content', 'remove_breadcrumbs');
function remove_breadcrumbs() {
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
}
Can anyone suggest what the current way to remove breadcrumbs from the Storefront theme is?
Okay, so I finally find the answer. The following code will remove the Storefront theme breadcrumbs:
add_action( 'init', 'wc_remove_storefront_breadcrumbs');
function wc_remove_storefront_breadcrumbs() {
remove_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
}
How can i change order of Up-sell & Related products sections on single product. It need to show first related products and then up-sell
Try the following that will move upsells after related products:
1) For Most themes:
add_action( 'init', 'move_upsells_after_related' );
function move_upsells_after_related( ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 25 );
}
Now in some themes like Storefront, a custom hook is used.
2) For Storefront theme only you will use instead:
add_action( 'init', 'move_upsells_after_related' );
function move_upsells_after_related() {
remove_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 25 );
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
I have a client who wants to pull the information that defaults into tabs on single product pages in WooCommerce into a different location on the page and remove the tabs entirely.
There are three default product tabs:
product Description,
Additional Information
and Reviews.
Removing the tabs and setting up the Description to display was easy enough to set up in
/wp-content/plugins/woocommerce/includes/wc-template-hooks.php:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
function woocommerce_template_product_description() {
woocommerce_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_description', 10 );
That works fine.
I tried to repeat the process by building out new functions that access the template files for Additional Info and Reviews like so:
function woocommerce_template_product_addinfo() {
woocommerce_get_template( 'single-product/tabs/additional-information.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_addinfo', 20 );
function woocommerce_template_product_reviews() {
woocommerce_get_template( 'single-product/review-rating.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_reviews', 30 );
But neither is displaying. What am I doing wrong here?
First woocommerce_get_template() is deprecated and replaced by wc_get_template() instead. After some searching and testing (mainly to get the reviews displayed), I have found the way:
add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
function removing_product_tabs(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'get_product_tab_templates_displayed', 10 );
}
function get_product_tab_templates_displayed() {
wc_get_template( 'single-product/tabs/description.php' );
wc_get_template( 'single-product/tabs/additional-information.php' );
comments_template();
}
Code goes in function.php file of your active child theme (or theme). Tested and work (WC 3+).
I have added the following code to the bottom of my functions.php file and they are not removing the functions from my product page. I copied the priority numbers directly from the content-single-product.php page and still no luck!
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price',10 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt',20 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart',30 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta',40 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_sharing' ,50);
remove_action('woocommerce_single_product_summary', 'WC_Structured_Data::generate_product_data()',60 );e
Try to include them in a custom function hooked in woocommerce_single_product_summary action hook with a smaller priority this way:
add_action('woocommerce_single_product_summary', 'customizing_single_product_summary_hooks', 2 );
function customizing_single_product_summary_hooks(){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_title', 5 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_rating', 10 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_price',10 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_excerpt',20 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart',30 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_meta',40 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_sharing' ,50);
remove_action('woocommerce_single_product_summary','WC_Structured_Data::generate_product_data()',60 );
}
Code goes in function.php file of your active child theme (or active theme).
This way it should work
Here's a part of codes in wc-template-hooks.php:
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
Here's the code from content-single-product.php
do_action( 'woocommerce_after_single_product_summary' );
What code should I put in content-single-product.php to remove woocommerce_output_related_products without editing the wc-template-hooks.php.
Sorry, I'm new in PHP. Thanks in advance.
You dont have to put it in content-single-product.php, try adding it to functions.php and if you just need to remove it on a single products page use woocommerce conditional functions to allow it only on the pages you want. for instance.
<?php if(is_product()){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); }?>
I have tried all above solutions but not working. Woo-commerce Version 3.4.1
Working Code, Added in child theme in functions.php
add_filter('woocommerce_product_related_posts_query', '__return_empty_array', 20);
If I correctly understood your question, put this in the functions.php inside your theme folder:
<?php
function woocommerce_remove_related_products() {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
add_action('woocommerce_after_single_product_summary', 'woocommerce_remove_related_products');
?>
You can remove action try adding it to functions.php -
add_filter( 'body_class', 'remove_action_from_woocommerce');
function remove_action_from_woocommerce()
{
if(is_product()){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); }
}
}
Here you can get WooCommerce Action and Filter Hook
-https://docs.woothemes.com/wc-apidocs/hook-docs.html