I'm trying to hide breadcrumbs with a child theme of storefront. This is the code I have in functions.php however, the conditional does not fire when on the cart page. Removing the conditional causes the breadcrumbs to be hidden
add_action('init', 'remove_shop_breadcrumbs' );
function remove_shop_breadcrumbs()
{
if ( is_cart())
{
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10 );
}
}
From everything I can read, this is correct, does storefront replace this conditional with its own code, hence causing this to fail?
You're code is firing too early. The init hook is triggered before the queries have been run therefore is_cart() won't work. Use the wp action instead.
Change this:
add_action('init', 'remove_shop_breadcrumbs' );
To this:
add_action( 'wp', 'remove_shop_breadcrumbs' );
Related
This question already has answers here:
remove_action() not working in WordPress plugin
(4 answers)
Removing functions from Woocommerce hooks
(2 answers)
Closed 2 years ago.
The WooCommerce plugin is inserting a script into the footer of my site. I have been attempting to remove this, but nothing seems to be working.
The following action is used to add the script to the footer:
add_action( 'wp_footer', 'wc_print_js', 25 );
I have tried removing this by placing the following in the child theme function file:
add_action( 'after_setup_theme', 'remove_wc_plugin_function', 0 );
function remove_wc_plugin_function() {
remove_action( 'wp_footer', 'wc_print_js' );
}
Have also tried just replacing the whole wc-core-functions.php file in my child theme, and commenting out the relevant functions, but that also doesnt work. I assume the function does not exist when the child theme function file is run. I then attempted to remove all jquery from the home page, which also doesnt get remove the script.
add_action( 'wp_enqueue_scripts', 'my_deregister_javascript' );
function my_deregister_javascript() {
if ( is_front_page('home') ) {
wp_deregister_script( 'jquery' );
}
}
Have also tried just replacing the whole wc-core-functions.php file in my child theme, and commenting out the relevant functions, but that also doesnt work. How can get I get rid of this bloody script in the footer (or preferably just get rid of a specific function)?
TLDR: How to remove a Wordpress plugin function, the script that was inserted with that function?
https://developer.wordpress.org/reference/functions/remove_action/:
To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added.
The function was added to the hook using
add_action( 'wp_footer', 'wc_print_js', 25 );
but you tried to remove it using only remove_action( 'wp_footer', 'wc_print_js' );, and then it will use the default value 10 for that third parameter.
So the correct way here to remove this function from the action again should be
remove_action( 'wp_footer', 'wc_print_js', 25 );
Within WooCommerce I have been making some edits to templates. So far this has been straight forward.
Now I am trying to add some columns into the 'Order Details' table under 'my-account > view-order'.
I am in the template view-order.php which is a template under 'myaccount' in WooCommerce.
Instead of seeing some code in a template to edit, I am seeing the following code:
<?php do_action( 'woocommerce_view_order', $order_id ); ?>
Where is the code from this action called and can I edit it?
Thanks for all time and help.
You need to look at WooCommerce plugin includes/wc-template-hooks.php core file (line 259):
add_action( 'woocommerce_view_order', 'woocommerce_order_details_table', 10 );
As you can see, the function woocommerce_order_details_table() is hooked in. So now let's find this function that is located in includes/wc-template-functions.php core file (starting line 2584).
As you will see this hooked function call the template file order/order-details.php.
So now you can make some changes:
1). Overriding the template file order/order-details.php via your active child theme or theme as explained in this documentation.
Note: The template file order/order-details.php is also used in Order received (thankyou), so take care to target your changes using the following condition:
// For view order
if ( is_wc_endpoint_url( 'view-order' ) ) {
// Here your changes
}
// For other cases
else {
// Here keep the original code
}
2). Or/and you could also remove this hooked function to replace it by your own custom function, with something like:
remove_action( 'woocommerce_view_order', 'woocommerce_order_details_table', 10 );
add_action( 'woocommerce_view_order', 'custom_order_details_table', 10 );
function custom_order_details_table( $order_id ) {
if ( ! $order_id ) {
return;
}
// Here below add your own custom code
}
You can also call your own custom template in that custom function, that will be used exclusively in order view endpoint...
Related: WooCommerce action hooks and overriding templates
WooCommerce Documentations:
Template structure & Overriding templates via a theme
WooCommerce Conditional Tags
i want to hide wp menu from my admin dashboard..
how remove/hide wordpress menu from admin dashboard .. i was try many code seems not work
I want to hide wpchtmlp_page menu item s. How to remove wpchtmlp_page menu item in admin page?
add_action('admin_menu', 'remove_admin_menu_items', 9999);
remove_menu_page( 'edit.php?post_type=wpchtmlp_page' );
You don't appear to be adding an actual function to the admin_menu hook. With the code you provided, it looks like you're adding a (potentially non-existent?) function to the admin_menu hook, and calling remove_menu_page without being on a hook, so it's firing way before the page is actually added.
add_action( 'admin_menu', 'so_59866103_remove_menu_items', 999 );
function so_59866103_remove_menu_items(){
remove_menu_page( 'edit.php?post_type=wpchtmlp_page' );
}
Generally speaking, you can also use a hook that runs later and before rendering (such as admin_init), which can be especially useful if that menu item was added in an unorthodox way.
add_action( 'admin_init', 'so_59866103_remove_menu_items', 999 );
function so_59866103_remove_menu_items(){
remove_menu_page( 'edit.php?post_type=wpchtmlp_page' );
}
You can remove menu from admin dashboard. Also you can remove any submenu as well. follow the sample code
function remove_item_from_menu() {
remove_menu_page( 'edit.php?post_type=elementor_library' ); // removes elementor addons , menu item added by plugins
remove_menu_page( 'edit-comments.php' ); // removes comment menu
remove_submenu_page('themes.php', 'theme-editor.php'); // remove submenu called theme edititor inside appearance
remove_submenu_page('themes.php', 'widgets.php'); // removes widgets submenu
}
add_action( 'admin_init', 'remove_item_from_menu' );
I am trying to remove the structured data that Woocommerce adds to the product pages.
I did some research and found that WC_Structured_Data::generate_product_data() generates the structured data markup. It's hooked in the woocommerce_single_product_summary action hook in the woocommerce/templates/content-single-product.php template file.
I tried by adding the following code to the functions.php
remove_action( 'woocommerce_single_product_summary', 'WC_Structured_Data::generate_product_data()', 60 );
So structured data wouldn't be added by Woocommerce, but it doesn't work…
Am I doing something wrong? Is there another way to do what I am trying to achieve?
Instead, you can use dedicated filter hook 'woocommerce_structured_data_product' that is located in WC_Structured_Data for generate_product_data() method nulling the structured data output in single product pages:
add_filter( 'woocommerce_structured_data_product', 'structured_data_product_nulled', 10, 2 );
function structured_data_product_nulled( $markup, $product ){
if( is_product() ) {
$markup = '';
}
return $markup;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
I suspect people want to remove the default tabs and they come here after they see the Woocommerce content-single-product.php template. In this template you see that generate_product_data() is hooked with priority 60.
After inspecting the hooks that run on woocommerce_single_product_summary.
You can easily remove the tabs with:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 60 );
I think Woocommerce forgot to mention this add_action.
This is how you can remove hooks associated with instantiated object method. You have to find the variable that holds the new Object instance.
In this case the main WooCommerce object is accessible as $GLOBALS['woocommerce'] and it has public property $structured_data which holds an instance of the WC_Structured_Data object.
Hence, to remove the hook in the question you can write this code:
remove_action( 'woocommerce_before_main_content', array( $GLOBALS['woocommerce']->structured_data, 'generate_website_data' ), 30 );
Add to functions.php:
add_action('wp_loaded', function() {
remove_action('woocommerce_single_product_summary', [$GLOBALS['woocommerce']->structured_data, 'generate_product_data'], 60);
});
Unhooks WC_Structured_Data::generate_product_data(). Will not waste resources on generating product data first for no reason and then "nulling" that same generated data a moment later using a filter.
i'm trying to change the order of my product page in woocommerce but i have a few problems with the remove_action().
I activated the child theme and in my functions.php i'm tryin to remove the add-to-cart button to add it back on another position.
I tried to put my remove_action() into a function that gets executed right after my parent theme loads.
function change_order() {
add_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 15 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
}
add_action( 'after_setup_theme', 'change_order' );
The add_action gets excuted but the remove_action() isn't working...
I tried the same with 'init' instead of 'after_setup_theme' but it is still not working...
Does anybody know a solution for my problem ?
Use a different single product hook
add_action('woocommerce_single_product_summary','change_order' );
function change_order() {
add_action('woocommerce_product_meta_end','woocommerce_template_single_add_to_cart', 15 );
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
}
Works and tested.