I want to remove "Add To Card" or any other button on home page of WooCommerce Theme but not from product single page.
For example:
Home Page: https://demo.woothemes.com/storefront/
Product Single Page: https://demo.woothemes.com/storefront/product/build-your-dslr/
I don't want to show any button on home page under product.
But I want to show button on product page.
I want to do this because i want to force my website visitor to visit product single page.
Which code line will I remove from website > Appearance > Editor?
Try the following:
add_action( 'woocommerce_after_shop_loop_item', 'remove_loop_add_to_cart_on_home', 1 );
function remove_loop_add_to_cart_on_home() {
if( is_front_page() ){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
}
Code goes in function.php file of your active child theme (or active theme).
To remove it on shop page too you will have:
add_action( 'woocommerce_after_shop_loop_item', 'remove_loop_add_to_cart_on_home', 1 );
function remove_loop_add_to_cart_on_home() {
if( is_front_page() || is_shop() ){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
}
Code goes in function.php file of your active child theme (or active theme).
See Woocommerce conditional tags
Related
This code works perfectly except I'm trying to determine how to EXCLUDE the main shop page from being included in the action. This hook adds the HTML code to all archive-type pages including the main shop page. Given this is a link back to the shop page, it should be excluded on the shop page.
Any help would be greatly appreciated.
function add_back_to_catalog_category() {
?>
<div><br><p class="button-catalog">Back to Catalog - All Products</p></div><?php
}
add_action( 'woocommerce_after_shop_loop', 'add_back_to_catalog_category' );
Visual reference to woocommerce_after_shop_loop action hook.
You can use the WooCommerce conditional tag is_shop() like:
add_action( 'woocommerce_after_shop_loop', 'add_back_to_catalog_category' );
function add_back_to_catalog_category() {
// Not on shop page
if( ! is_shop() ) {
printf( '<div><br><p class="button-catalog">%s</p></div>',
get_permalink( wc_get_page_id( 'shop' ) ),
__("Back to Catalog - All Products", "your-text-domain")
);
}
}
Code goes in functions.php file of the active child theme (or active theme). It should works.
How to hide product "Description" tab' in Woocommerce plugin only for unlogged users, but visible for registered customers (and logged-in users).
To remove product description tab on sigle product pages for non logged users, you will use:
add_filter( 'woocommerce_product_tabs', 'customize_product_tabs', 100 );
function customize_product_tabs( $tabs ) {
if ( ! is_user_logged_in() ) {
unset( $tabs['description'] ); // remove the description tab
}
return $tabs;
}
This code goes in functions.php file of your active child theme (or active theme). Tested and works.
Try this, add this snippet into the function.php
add_action( 'init', 'hide_price_add_cart_not_logged_in' );
function hide_price_add_cart_not_logged_in() {
if ( !is_user_logged_in() ) {
//Remove short description (excerpt) from single product page
remove_action( 'woocommerce_product_tabs', 'woocommerce_template_single_excerpt', 20 );
}
}
I want to not display the stars on products in the Shop page loop. My current code doesn't work...
I'm working on a WooCommerce website with Astra.
function no_stars_if_no_reviews() {
global $product;
if ($average = $product->get_average_rating()) :
if($average > 0) {
remove_filter(get_average_rating);
}
}
I just want to remove the filter when no reviews are there, but keep it otherwise. Once again, this is for the Products page, NOT single.
Simply use the following, to remove rating stars from shop and archive pages when no reviews:
add_action( 'woocommerce_after_shop_loop_item_title', 'conditionally_remove_loop_rating', 4 );
function conditionally_remove_loop_rating(){
global $product;
if( ! ( $product->get_review_count() > 0 ) ) {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
I have woo commerce site, but in few specific product pages i don't want to show products images. How can i hide product image in specific pages only? once hide/remove product image, need to speared the text/content.
This can be done with this simple code:
add_action( 'template_redirect', 'single_product_remove_images', 1 );
function single_product_remove_images() {
// HERE below set your Page ID, title or slug
if( is_page( 56 ) ){
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
If you want to target a post id istead, you will use something like if( get_the_id() == 56 ){
I have tried many code examples and none of them have worked.
My site has 2 main categories (New & Used) each have about 10 sub cats with them. I am using the YITH request a quote plugin but I only want to use it on the Used items, Is there a way I can display the Add To Cart button for just the New category?
the url is set up like site.com/used-equipment/sub-category/product-name/
Here is the code I have tried.
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
if( is_product_category( array( 'used-equipment' )) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
}
— Updated —
You need to use has_term() conditional function to make it work. has_term() accept category or subcategory names, slugs or Ids, (a single string or an array of values).
Here is your changed code:
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
if( has_term( 'used-equipment', 'product_cat')) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
}
This code is tested and works. It removes on the shop pages and on archives pages the add-to-cart button on products that belongs to a defined category or subcategory…
This goes in function.php file of your active child theme (or theme) or also in any plugin file.