storefront_sticky_add_to_cart refuses to be removed - wordpress

Almost finished my WooCommerce Storefront child theme.
There's a block sitting under the footer on the product pages that I have zero desire to keep. Just as I've done with a few other extraneous pieces of markup, I tracked down the action and removed it:
remove_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart');
... It is still showing in the page.
I've even tried some random things I found:
add_filter ('storefront_sticky_add_to_cart', '__return_false');
and
function cleanup_parent_filters()
{
//...
remove_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart');
}
add_action( 'wp_loaded', 'cleanup_parent_filters');
With no results.
This is really more annoying than anything. I can remove the entire do_action( 'storefront_after_footer' ); from the template as I really just don't care to have it there, but now I need to know why this is not working as expected out of principle.

try
remove_action( 'storefront_after_footer',
'storefront_sticky_single_add_to_cart', 999 );
remove_action needs the priority value as it was used to add the action. From the Docs
Important: To remove a hook, the $function_to_remove and $priority
arguments must match when the hook was added. This goes for both
filters and actions. No warning will be given on removal failure.
And why 999? From the source code.
Disclaimer: I haven't tested this out.

Related

remove_action is not working for me to remove a theme's action..?

I'm running WordPress + WooCommerce + Storefront. I'm trying to remove the "Built with Storefront & WooCommerce" credit in the footer.
I see lots of articles explaining how to do that by using remove_action as follows:
remove_action('storefront_footer', 'storefront_credit',20);
This is not working, though. I've tried it through a Snippets plugin, and I've tried it through the functions.php in my child theme.
I've also verified that nothing seems to have changed in the theme code since these articles were written, so it has the same function and hook names.
I'm not sure what I'm missing here..?? Any information on this would be greatly appreciated. Thanks!
In order to remove the action you must be sure to remove it before it's added. This is a parent theme's hook, so if you remove_action from the child theme or via code Snippets, it's already too late.
Unless... you make the remove_action trigger earlier, by hooking that to "wp" WordPress action.
Try with:
add_action( 'wp', 'bbloomer_remove_storefront_actions' );
function bbloomer_remove_storefront_actions() {
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
Another cool thing you can do to absolutely make sure you can remove an action is by using the same hook, but with a lower priority:
add_action( 'storefront_footer', 'bbloomer_remove_storefront_actions', 19 );
function bbloomer_remove_storefront_actions() {
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
In this example, I'm removing 'storefront_credit' which has priority = 20 by hooking into the same hook, with priority 19, so that I remove it before it's added.

How to safely remove an action hook in child-theme?

I am working on a WordPress installation called PointFinder. Items that are posted by users get deleted after some pre-defined period. My goal is to disable this behaviour. I already found the corresponding code lines and deactivated the add_action hook that triggers the periodically called function pointfinder_clean_pending_orders() in schedule-config.php, which works fine for the moment.
add_action( 'pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders' ); // <--- commented out this line
function pointfinder_clean_pending_orders() {
/* code that cleans-up ... */
}
How can I achieve the deactivation in my child-theme ? If I simply add a remove_action to functions.php in my child-theme, will that work? I am not sure what will be called first, add_action in schedule-config.php or my remove_action in functions.php ?
I only have access to the productive server and no testing environment and thus I am a bit reluctant regarding experiments.
try this:
add_action('init','remove_hourly_hook');
function remove_hourly_hook() {
remove_action( 'pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders' );
}
What this does is after WordPress is initialized (regardless of the order of functions.php being called), it will then remove the action.
Now, if the initial add_action is inside a its own hook, you will want to make sure your hook 'init' is changed to occur afterwards.

Removing action added by a plugin in Wordpress

I am using Popup Maker plugin for Wordpress and I am trying to prevent it to load on a particular page using the functions.php file of a child theme.
I've located in the plugin's directory the file popup-maker.php which contains the following line at the end:
add_action( 'plugins_loaded', 'popmake_initialize', 0 );
If I remove / comment this line, the popup will not fire, so I guess this is the action I need to remove. I have read the WP codex and numerous posts but still can't get it to work.
Right now I am stuck at this (function I have added in my child theme's functions.php file):
function remove_popmaker() {
remove_action('plugins_loaded', 'popmake_initialize', 0);
}
add_action( 'init', 'remove_popmaker', 1 );
PS: I am using shopkeeper theme and Woocommerce.
All help appreciated, thanks.
you are adding a action to init which is after plugins_loaded so you cannot remove a action after it has run.
you can try the same action but you will have to do this from a plugin
remove_action( 'plugins_loaded', 'remove_popmaker', 0 );
But i suspect actions added before yours will be run after, this may be unpredictable if not you may have to code a MUplugin (google this).
There is a way I managed to do this:
add_action('wp', 'disableEmailPopup');
function disableEmailPopup () {
global $post;
if ($post->ID === 11625249) return remove_action( 'wp_enqueue_scripts', 'popmake_load_site_scripts');
}
#BMM - Without knowing the use case as to why you need to disable the entire plugin on one page its hard to give you the best answer.
For example if you simply wanted a single popup to not show on one page you can use the conditions panel to add a negative condition using the (!) button. Click it to turn it red and you will check for the opposite of a condition, so (!) Page Selected: Page xyz would prevent it from loading on that page.
Alternatively you can create your own custom conditions allowing you to add that condition to any popup.
Lastly if you wanted to unhook it just from the front end you can simply remove the rendering & script handlers
remove_action( 'wp_footer', 'popmake_render_popups', 1 );
remove_action( 'wp_head', 'popmake_script_loading_enabled' );
And if you want to prevent the queries as well
remove_action( 'wp_enqueue_scripts', 'popmake_preload_popups', 11 );
Hope that helps.

the_excerpt and the_content filters

I'm in a kind of a bind. I'm adding rating to posts in WP. It's done with the_content filter. Thing is, some themes use excerpt instead of content in, say, archive loops. Adding rating to that is as simple as just adding filter for the_excerpt. Problem is, when excerpt is retrieved by theme, it fires the_content filter too (so rating is actually added), but after that, content is stripped off all html tags, so rating as it is (shapes) is gone but vote counter remains. This leads to non pretty situation like this:
Now I'm wondering what's the good way around it? I don't think there is a way to see list of actions which will call action handler for the current post (so that if action handler is called from the_content filter (check by current_filter()) and there is the_excerpt in 'queue' for this post just return content without changes) or a way to know to know if the_content was fired by function to retrieve excerpt. Of course, very dirty and horrible workaround would be to check content for vote counter text when action handler is fired by the_excerpt and just replace it with empty string but that's not a good solution. Am I missing something here? Is there a cleaner way of doing this?
Ok, the cleanest solution I could come up with is this
function remove_mah_filter($content)
{
if (has_filter( 'the_content', 'your_filter' ))
{
remove_filter( 'the_content', 'your_filter' ); // if this filter got priority different from 10 (default), you need to specify it
}
return $content;
}
add_filter('get_the_excerpt', 'remove_mah_filter', 9); //priority needs to be lower than that of wp_trim_excerpt, which has priority of 10. Otherwise, it will still be triggered for the first post in the loop.
// add it back so that it can be called by the actual content
function readd_mah_filter($content)
{
add_filter( 'the_content', 'your_filter' ); // if this filter got priority different from 10 (default), you need to specify it
return $content;
}
add_filter('get_the_excerpt', 'readd_mah_filter', 11); //priority needs to be higher than that of wp_trim_excerpt, which has priority of 10.

WordPress Thesis theme - hook below post

i need a little help with thesis theme, i made a simple hook for single post with custom content and i want the hook to be right after the post but after the post there's a plugins like facebook etc... and my hook is below that. How to make my hook to be right after post without disabling this plugins ?
*i already tried every posible combinations thesis_hook_after_post, thesis_hook_after_post_box etc and it dont work
Thanks in advance !
Change priority value in add_action
add_action( $tag, $function_to_add, $priority, $accepted_args );
(int) (optional) Used to specify the order in which the functions
associated with a particular action are executed. Lower numbers
correspond with earlier execution, and functions with the same
priority are executed in the order in which they were added to the
action. Default: 10
Edit:-
function post_article111() {
if (is_single( )) {
echo "content goes here..";
}
}
add_action('thesis_hook_after_post_box', 'post_article111','5');

Resources