How to remove Woocommerce cart notifications? - php

Question:
How to remove the Woocommerce cart notifications as: "Product was removed from cart", "Product was added to your cart", "Show cart".
Platform:
Wordpress & Woocommerce
Theme:
Astra
Plugin:
Elementor Pro
See photos for notifications I want to be removed.
Added to cart:
Removed from cart:
What I have already done is removing the coupon code from the checkout page through some code in the functions.php but I don't know if it's possible to remove these notifications through code or other options?

Here is hook to remove "Add to cart notifications" use this in functions.php
add_filter( 'wc_add_to_cart_message_html', 'dont_show_message');
function dont_show_message( $message, $products ) {
return '';
};
Or simply yon can use CSS to hide the same.

Related

Remove mini cart menu from sidebar and redirect to checkout page

I'm using theme called Blance on my site, but want to remove right sidebar mini cart widget which appears when you add some product to cart. I tried this:
Disabled "Redirect to the cart page after successful addition" and "Enable AJAX Buy Now buttons on archives" from WooCommerce settings.
After that added this function into functions.php file:
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_checkout_redirection', 10, 1 );
function add_to_cart_checkout_redirection( $url ) {
return wc_get_checkout_url();
}
But seems that products still appears in the right sidebar cart after pressing Buy Now button. How to override that, and redirect to checkout directly?

How to remove woocommerce added cart items and redirect to checkout?

I have a Woocommerce form to 'Add Funds'. It has an amount input field ($20, $30 ...etc.) and a submit button that redirects to cart page with the input amount as total.
Redirect to checkout is working, but the cart items are not getting removed if a user abandons the cart and tries to order again.
I tried numerous solutions for the redirect to checkout, but only one worked.
Working solution for redirect to checkout:
WooCommerce - Skip cart page redirecting to checkout page
Solutions not working for redirect to checkout:
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Woocommerce add to cart button redirect to checkout
N.B. I have added the working and not working solutions for redirect
to checkout because it may provide an insight as to why the empty cart
solutions are not working.
Incase of emptying cart before adding a new product, none of the solutions are working:
https://gist.github.com/viniciusrtf/b49403b5f87dcd7699c1
https://hungred.com/how-to/empty-woocommerce-cart-adding-item/
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Using Woocommerce 3.2.6 and WordPress 4.9.2
First you will need in WooCommerce Settings > Products > Display in "Add to cart behaviour" to enabled the checkbox : Redirect to the cart page after successful addition
Then you will need the 3 following hooked function:
1) Empty cart before add-to-cart (if cart is not empty)
add_filter( 'woocommerce_add_to_cart_validation', 'one_cart_item_at_the_time', 10, 3 );
function one_cart_item_at_the_time( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty())
WC()->cart->empty_cart();
return $passed;
}
2) Add-to-cart redirection to checkout:
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_checkout_redirection', 10, 1 );
function add_to_cart_checkout_redirection( $url ) {
return wc_get_checkout_url();
}
3) Skip cart page redirecting to checkout:
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
function skip_cart_page_redirection_to_checkout() {
if( is_cart() )
wp_redirect( wc_get_checkout_url() );
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works (with Woocommerce 3.2.6 and WordPress 4.9.2 on Storefront theme).

Disable ajax for add to cart button in single product page / Wordpress / Woocommerce

I am developing an eCommerce website using wordpress, cartify theme, woocommerce 3.0.3.
I would like to redirect after to cart or checkout after clicking the buy now product.
Here you can see the page
**Add to cart behaviour**
✔︎ Redirect to the cart page after successful addition
(Unchecked) Enable AJAX add to cart buttons on archives
I activated redirect to cart after add to cart click and left in the woo commerce options but it seems to still using ajax.
**WooCommerce System status**
MySQL version: 5.5.51 - We recommend a minimum MySQL version of 5.6.
(THE HOST PROVIDER DOESN'T ALLOW ME TO UPGRADE)
WC pages
My account: Page does not contain the shortcode.
cartify/woocommerce/single-product/product-image.php version 2.6.3 is out of date. The core version is 3.0.2,
cartify/woocommerce/single-product/product-thumbnails.php version 2.6.3 is out of date. The core version is 3.0.2,
This two really mess my site when I update them.
Any suggestions, please?
Thank you in advance for your help
SO here I am going to explain three steps
Step 1 if you want customer to redirect after adding to cart to checkout then add below code to the functions.php
function my_custom_add_to_cart_redirect( $url ) {
$url = WC()->cart->get_checkout_url();
// $url = wc_get_checkout_url(); // since WC 2.5.0
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
Step 2 if you want customer to redirect to the cart page after add to cart the following image link showing you can do this from admin end
http://prntscr.com/ewo99j
Step 3 if from admin end it's not redirecting the customer to the cart page then add following code to your functions.PHP
function custom_add_to_cart_redirect() {
return 'http://localhost:8080/wordpress2/cart/';
}
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
replace this URL http://localhost:8080/wordpress2/cart/ with your cart page URL
hope it will work for you
Thanks
You can use this jquery in your theme.
$(document).ready(function() {
$(".add_to_cart_button").removeClass("ajax_add_to_cart")
});
Then you can use this code in your functions.php for redirect into the checkout page:
add_filter('woocommerce_add_to_cart_redirect','themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}

Insert short description after YITH Wishlist button

I'm using YITH WooCommerce Wishlist plugin and in my WooCommerce single product pages, I'm trying to insert the "Short description" block after the YITH Wishlist button.
My wishlist html element is:
<div class="yith-wcwl-add-to-wishlist add-to-wishlist-48">
label
<div class="yith-wcwl-wishlistaddresponse"></div>
</div>
What is the tag to add action so that description goes after the element wish list?
My example code:
add_action('woocommerce_...','woocommerce_template_single_excerpt' );
Thanks.
That is possible easily and instead of moving the short description, you can place this Wishlist button before the short description. You will have first to change in the General settings of YITH WooCommerce Wishlist plugin, for "Position" you will choose "Use shortcode" and you will save that setting:
Then you will add a custom function hooked in woocommerce_single_product_summary action hook with a priority of 15 (between the product price (10) and the short description (20)):
add_action( 'woocommerce_single_product_summary', 'custom_yith_wcwl_add_to_wishlist', 15 );
function custom_yith_wcwl_add_to_wishlist(){
echo do_shortcode('[yith_wcwl_add_to_wishlist]');
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Related WooCommerce template: content-single-product.php
PHP Snippet: Display YITH Wishlist Buttons # Shop Page – WooCommerce YITH WooCommerce Wishlist Add code in your theme fuctions.php file
Then create a page for example (whislist) and [yith_wcwl_wishlist] paste short code there and update page and then go to YITH Plugin Settings then Select Wishlist Page (page name wishlist which you created).
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_display_yith_wishlist_loop', 97 );
function bbloomer_display_yith_wishlist_loop() {
echo do_shortcode( "[yith_wcwl_add_to_wishlist]" );
}

Disabling cart page

I would like to disable the WooCommerce cart functionality by all means.
My shop has only a single product, so cart is doesn't really needed.
My desired flow is Click on buy button -> go to checkout page.
Incase user goes back and redo the same process, checkout page will not show 2 products in summary buy just 1.
Any tips on how to achieve this smoothly ?
Thanks,
You will Need 4 code snippets:
1) Disabling quantities buttons (on product page):
add_filter( 'woocommerce_is_sold_individually', '__return_true' );
2) Add-to-cart validation, allowing just one product in cart:
add_action( 'woocommerce_add_to_cart_validation', 'check_product_is_in_cart' );
function check_product_is_in_cart() {
WC()->cart->empty_cart();
return true;
}
3) Checkout redirect customer when your product is added to cart (with modern syntax):
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
return WC()->cart->get_checkout_url();
// OR ALSO:
// return get_permalink(get_option('woocommerce_checkout_page_id'));
}
The code comme from this answer (with the correct new syntax): Woocommerce add to cart button redirect to checkout
4) Redirect Cart page to Checkout page (in case of):
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
function skip_cart_page_redirection_to_checkout() {
if(is_cart()){
wp_redirect(WC()->cart->get_checkout_url());
// OR ALSO:
// wp_redirect( get_permalink( get_option( 'woocommerce_checkout_page_id' ) ) );
exit; // This is mandatory with wp_redirect()
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Code is tested and works.
Disabling redirect to Cart on add-to-cart action and Ajax add-to-cart on Shop page and archives pages (optional)
You can also disable some settings in WooCommerce > Settings > Products > Display (tab).
Optionally keep that 2 options disabled (and save settings):
If you need to skip the cart page the easiest way it is to go to the Woocommerce->Settings->Checkout and set Cart Page to "Checkout" page
Or use this snippet
add_filter('add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
Don't forget to disable Ajax Add to cart and Redirect to the cart page after successful addition in Woocommerce->Settings->Products->Display
If you use the first method you can check the Redirect to the cart page after successful addition.
For the limit one item in checkout use this snippet.
In this way, the customer only can buy one item, if the customer goes to another product and tries to buy it, the cart will be cleaned and the last item added.
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
function woo_custom_add_to_cart( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
return $cart_item_data;
}

Categories