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

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/

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!

Conditionally Hiding Pricing; Need to Make Visible from Tag/Custom Taxonomy

Hide product pricing & add to cart button unless logged in
Sale items be visible, logged in or not, if visited from some kind of tag, category, or other taxonomy so that nobody sees the sales unless they are directed to them explicitly.
Example: All product prices are hidden, except on URLs with the tag "waffles-sale". This is a simple example but I think that explains what I'm after with 2.
I've accomplished 1. with a plugin, and more recently a short code; this works great:
add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
function bbloomer_hide_price_add_cart_not_logged_in() {
if ( ! is_user_logged_in() ) {
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 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
}
}
function bbloomer_print_login_to_see() {
echo '' . __('Please login for pricing.', 'theme_name') . '';
}
But this leaves me with two, which is making things visible conditionally. I am sorry if this is vague. I've scoured the web for answers but I'm coming up short. I feel like my vocabulary is holding me back; I don't know the words for the hooks or phrases that I'm describing. I would love to stop reinventing the wheel (I'm having to clone products/product categories to make only them visible from temporarily published pages for sales).
Can anyone point me in the right direction? Is controlling product visibility in this way possible? I would greatly appreciate anyone's more experienced two cents or solution to this. Thank you.
You could try this (haven't tested), wrote it on rush, but it should help you in achieving what you need.
You need to define the query string then add/remove actions depending on what you need based on that query string.
Use the get_query_string:
// register query var
add_action('init','register_query_string');
function register_query_string() {
global $wp;
$wp->add_query_var('my_query_string_name');
}
//check if it's in the url
if ( get_query_var('my_query_string_name') ) {
// remove/add actions for the query string
elseif ( !user_not_logged_in()){
//something when not logged in
}
}
in case you need to check for query string and logged in, you can do something like
if ( !get_query_var('my_query_string_name') && ( !user_not_logged_in()){
// insert magic here
}
Code goes into functions.php from your child theme (or a plugin).

I need a custom wc-template-functions.php file

I am trying to change the layout of my single product page. For this i need to change the file wc-template-functions.php (found in plugins/woocommerce/includes).
I know for changing the template files i have to copy the folder into my theme and rename it to "woocommerce" but how does it work for a file in the folder includes?
If you take a look at the template for the single product page, specifically content-single.php you will see that the product images are attached to the woocommerce_before_single_product_summary hook.
To remove them you would need to use remove_action() and then to place them somewhere else you attach them to a different hook via add_action():
function so_31406339_move_images(){
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images ', 20 );
// for example, to move them to the very bottom of the page:
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_show_product_images ', 30 );
}
add_action( 'woocommerce_before_single_product', 'so_31406339_move_images' );

WooCommerce main product image

I want to make a simple change to WooCommerce default template. Currently, the gallery displays on the left side just under the main image. I want it to display on the right side just under the short blurb description. I managed to do this by adding the following code to the functions.php file:
/*Relocate Product Gallery*/
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce-main-image', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_show_product_thumbnails', 100 );
The first line removes the group of images (main and gallery) from the left side.
The last line puts just the gallery exactly where I want it.
The middle line is the issue. I want just the main product image to appear where it should, but instead it's throwing an error. Am I using the wrong vaiable name to call just the main product image?
The short answer is that there is no function called woocommerce_main_image - you should be using woocommerce_show_product_images instead. If you check wc-template-hooks.php you'll see that it's hooked by default:
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
What's not clear is why it's not already showing - perhaps your template isn't calling the woocommerce_before_single_product_summary action.
You say you want to display the main image separately from the thumbnails; I'm going to give you the long-winded explanation as to how it all works so that you have a better understanding:
Have a peek at wc-template-functions.php - you'll find that the woocommerce_show_product_images() includes the product-image.php file via this line:
// wc-template-functions.php:716
wc_get_template( 'single-product/product-image.php' ); // Includes product-image.php
This displays the main image and has a hook for displaying the thumbnails:
// product-image.php:43
do_action( 'woocommerce_product_thumbnails' ); // woocommerce_show_product_thumbnails() is hooked to this
You can either create your own copy of product-image.php to override and remove the do_action() OR you can unhook the function that is actually displaying the thumbnails using remove_action(). If you look in wc-template-hooks.php again you'll see:
// wc-template-hooks.php:108
// This hooks the function to the action
add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
That's what's hooking in the function to the action. You can remove this by putting...
// This unhooks the function from the action
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails' );
... into your theme functions.php file. To display the thumbnails in a different location you can simply use either the woocommerce_show_product_thumbnails() function or wc_get_template( 'single-product/product-thumbnails.php' ) in your template; the former is simply a wrapper function for the latter.
Hopefully that's a clear enough explanation for you to figure the rest out. Good luck.
Thank you! Accomplished.
/*---Move Product Gallery*/
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_show_product_thumbnails', 100 );

Resources