Remove action woocommerce_single_variation_add_to_cart_button - woocommerce

In WooCommerce you can find this add_action:
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
I don't manage to REMOVE this action with below code:
function remove_loop_button(){
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
add_action('init','remove_loop_button');
I'm trying to understand why, please help.

This might be a issue that the remove_loop_button function is running much before the function 'woocommerce_single_variation_add_to_cart_button' is added.
Try to run on add_action( 'woocommerce_loaded','remove_loop_button' ); instead.

The problem was this was added since WooCommerce 2.4, at the time I posted it I had not updated my WooCommerce to 2.4 yet.

Related

remove_action hook not working to remove credit card fields from donation form GiveWP

I have used below action hook to hide fields but it is not working.
remove_action( 'give_cc_form', 'give_get_cc_form' );
can anyone help me to figure out this issue
I am using GiveWP plugin for donation in WordPress site.
GiveWP has a pretty expansive snippet library, and one example shows how you can remove and rearrange fields. This is probably the best place to start from:
https://github.com/impress-org/givewp-snippet-library/blob/master/form-customizations/customize-fieldset-order.php
function give_remove_fieldsets() {
remove_action( 'give_cc_form', 'give_get_cc_form' );
}
add_action( 'init', 'give_remove_fieldsets' );
this actually worked for me
Make sure to run it at init, and you need to add the same priority used in the add_action, if none it uses 10 and the priority can be left blank
add_action('init','remove_actions');
function remove_actions() {
remove_action( 'give_cc_form', 'give_get_cc_form', 1 ); // Replace the priority with the correct one
}

Woocommerce how to remove Variation select list and show it in a custom hook

In a Woocommerce Product Page I need to remove the Variation Select Lists from the default placement and show them y my custom hook:
"flatsome_custom_single_product_3"
How can I do this?
I tried with this, but not working.
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'flatsome_custom_single_product_3', 'woocommerce_single_variation', 10 );
Take a look at this capture to see what I mean:
You could first remove the default variation and then add your own using the following hook:
remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
add_action('woocommerce_variable_add_to_cart', 'custom_variable_div', 15);
add_action('woocommerce_variable_add_to_cart', 'woocommerce_single_variation_add_to_cart_button', 20);
function custom_variable_div(){
# Make up your own stuff
}
I've tested it and it works seamlessly fine!

Trying to Remove Wordpress Action in Plugin

I have a plugin that loads Google Fonts into head of the website but I want to remove that action. Here is how they do it:
add_action( 'wp_head', 'add_web_font', 0 );
I'm trying to remove it like this:
add_action( 'wp_head', 'remove_my_action', 20 );
function remove_my_action(){
remove_action( 'wp_head', 'add_web_font', 0 );
}
I'm not sure why the above is not removing it? I have my code placed in a plugin. Even with the priority to 0 it still does not stop the action.
In remove_action, you must also include the priority that was used when the action was defined, if it isn't the default value of 10. In your case the action was added with a priority of 0, so you need to use the following:
function remove_my_action(){
remove_action( 'wp_head', 'add_web_font', 0 );
}
Ref: Wordpress Codex: remove_action
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.
Thanks #FluffyKitten for getting me thinking in the right direction. I added my action to plugins_loaded to ensure it runs after. The working code is as follows:
function remove_my_action(){
remove_action( 'wp_head', 'add_web_font', 0 );
}
add_action( 'plugins_loaded', 'remove_my_action', 20 );
The Hook in Oxygen has changed to oxygen_enqueue_frontend_scripts
remove_action('oxygen_enqueue_frontend_scripts', 'add_web_font',0);
found in File component-init.php:4344 in Version 3.9

remove_action fails on woocommerce_template_loop_product_thumbnail

I wrote a simple plugin that performs some logic on thumbnails in WooCommerce. This plugin worked great for about a year, until the client switched to a new theme. Now the plugin is no longer working and I've narrowed the problem to remove_action() failing.
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
if (! remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10) ) {
echo 'FAILED to remove action<br/>';
}
/**
* WooCommerce Loop Product Thumbs
**/
if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
function woocommerce_template_loop_product_thumbnail() {
echo woocommerce_get_product_thumbnail();
}
}
I don't know if this is because of the order plugins are loaded, or if I'm making the call incorrectly due to a change in WooCommerce. I've read some topics that indicate the remove_action() should follow my custom add_action() so I reversed the order accordingly. It doesn't work either way - remove_action() is always returning FALSE.
I've been banging my head against a wall all day trying to figure this out. Can anyone give me a clue on a sure-fire way to execute the remove, or a way to debug it?
Thanks.
Try changing the priority flag of [add/remove]_action() to something higher, like 90.
It's a little hard to guess without seeing what the theme is actually doing!
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 90);
if (! remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 90) ) {
echo 'FAILED to remove action<br/>';
}

Woocommerce - How to remove the Add to Cart Button on product listing

I'm wanting to remove the Add to Cart Button on the product listing pages. The only place I want it to appear is the individual product page. Can anyone suggest on where I can find to remove this? I haven't been able to get any help from the documentation.
At the moment the button appears under every listing.
I don't know how to do it from WooCommerce but with following code it is possible, just make sure that these PHP code should execute, so, put it at suitable place in PHP file where some PHP codes are executing, best place would be any wordpress plugin's base file, be careful while updating that plugin as these code will get lost after updating.
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
We have found the answer by coding a little bit, in wordpress:
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
add_action('init','remove_loop_button');
here: https://www.igniweb.com/remove-add-to-cart-button-wordpress/
You can remove the add to cart button from product pages by adding this in woocommerce.php (located wp-content/plugins/woocommerce)
function Wp() {
remove_action( 'woocommerce_after_shop_loop_item',
'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart');
return WooCommerce::instance();
}
After adding this code, reload the page and you will see that the button has been hidden.
You can also remove the add to cart button from specific Product pages using this code in functions.php (located in the theme folder):
add_filter('woocommerce_is_purchasable', 'wp_specific_product');
function wp_specific_product($purchaseable_product_wp, $product)
{
return ($product->id == specific_product_id (512) ? false :
$purchaseable_product_wp);
}
For reference you can see
https://wpitech.com/hide-disable-add-to-cart-button-in-woocommerce-store/

Resources