Backorder Notification Woocommerce - woocommerce

I have a little problem with the backorder notification on my woocommerce shop.
What it is now: I set in the product backorders: allowed, but notify customer. When I press a variaton on the product page it will show available for backorder. So far so good. When someone place the order it will show the text backorderer: 1 on the order confirmation, on the pdf invoice, on the e-mail.
What I want: Show the notification only on the product information page. Not on the e-mails, order confirmation, etc. But when I set up backorders only to allow. There is also no notification on the Product Page for the customer.
So do someone of you know, how I can change this? Is there a custom code or something else I can use.
This is really important for me. I tried to find a solution about 1 week without any luck. So please help me.

Can you try this?
Just copy and paste this block of code to your functions.php file in your child theme.
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2); function wcs_custom_get_availability( $availability, $_product ) { // Change In Stock Text if ( $_product->is_in_stock() && ! $_product->backorders_allowed() ) { $availability['availability'] .= __('<br />Shipped immediately', 'custom'); } if ( $_product->is_in_stock() && $_product->backorders_allowed() ) { $availability['availability'] = __('<br />We will inform you via email when the product is back in stock. Please send us your contact info via the form below.', 'custom'); } // Change Out of Stock Text if ( ! $_product->is_in_stock() ) { $availability['availability'] .= __('<br />We will inform you via email when the product is back in stock. Please send us your contact info via the form below.', 'custom'); } return $availability; }
And let me know whether it worked for you or not.
Thank you

Related

How to remove quantity from cart page in WooCommerce for downloadable items

Thanks in advance for anyone who can help with this. As I have many virtual/ downloadable items in my Woocommerce shopping page, is there a way to disable, or make the quantity field disappear, entirely but only for those types of items? I have had several occurrences where customers bought multiple of something that was digital, and since that didnt make much sense because they could download it multiple times, I wound up manually refunding the extra. To avoid this extra work, can qty get turned off if the downloadable checkbox is ticked on the product page, or something like that? And it just keeps the default qty of 1 during checkout.
Give this a try
function hide_downloadable_quantity_field_cart( $product_quantity, $cart_item_key, $cart_item ) {
if ( isset( $cart_item['data'] ) && $cart_item['data']->is_downloadable() ) {
$product_quantity = '';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', 'hide_downloadable_quantity_field_cart', 10, 3 );
It should remove the quantity field completely for downloadable items in the cart.

Hide & refresh WooCommerce checkout after add coupon

We want to hide "Have a coupon? Add one..." on WooCommerce checkout, if a coupon is already added OR when a customer add a coupon on the checkout page.
Currently we habe this code below and it works when a customer enters a coupon on the cart page and then navigate to the checkout page. In this case, the "Have a coupon? Add one..." message is not visible. If no coupon in added on the cart page the message is visible.
This is working fine! But it does not work when a customer adds a coupon on the checkout page.
1.) We get the message "Coupon added" But the coupon message to add one is still visible AND also the coupon is not calculated in the order table. => After a page refresh is everything correctly.
2.) When a coupon is removed by the customer on checkout, then we get the message that the coupon is removed, but the discount is still visible in the order table. => After a page refresh it displays everything right again.
So now I'm trying to refresh the page after a coupon was added or removed. But I have problems to get the right event. I guess we must do this via js? Or is there a PHP approach?
add_filter( 'woocommerce_coupons_enabled', 'woocommerce_coupons_enabled_checkout' );
function woocommerce_coupons_enabled_checkout( $coupons_enabled ) {
global $woocommerce;
if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
return false;
}
return $coupons_enabled;
}
Your code should be like this
add_filter( 'woocommerce_coupons_enabled', 'woocommerce_coupons_enabled_checkout' );
function woocommerce_coupons_enabled_checkout( $coupons_enabled ) {
if(is_checkout()){
global $woocommerce;
if ( ! empty( $woocommerce->cart->get_applied_coupons() ) ) {
$coupons_enabled = false;
}
}
return $coupons_enabled;
}
Edit: okay you need to check if page is checkout or cart then run the script. I have added condition in code.

Display Notice on product page after Review Submit in WooCommerce

I am using the code below to "re-direct" back to the product page because if not, the page stays at the "bottom" where the review form is.
My question is this:
how do I print / display a message on the product page after the review has been submitted by the customer?
Here's my code:
add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment($location) {
$location = wp_get_referer();
wc_add_notice( __( 'Thank you for writing a review. Use this coupon code <code>FIVEOFF</code> on the checkout and get $5 OFF!', 'woocommerce' ), 'success' );
return $location;
}
Problem is, the message is not being displayed and I tried adding in a do_action for wc_notice which did not help either.
You should put wc_add_notice() before return $location;. Because return stops the execution of the function and sends the value back, so the statements after it won't be executed.

Refreshing a WordPress Page using JavaScript

I am creating a custom cart for a website, and i am still a beginner.
I am using Wordpress/woocommerce functions to add or delete from the cart, but after submiting my changes i want the page to be refreshed so i used javascript to do that.
location.reload();
however this is taking me back to the home page but with a url having the item id that i deleted from the cart.
is there a better way to refresh wordpress pages, or should location.reload() make no issues?
this is a php snippet of how i am deleting an item, i am also concerned that this snippet is responsible for taking me back to the homepage
$prod_to_remove = $values[product_id];
// Cycle through each product in the cart
foreach ( $WC->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the Variation or Product ID
$prod_id = $cart_item['product_id'];
// Check to see if IDs match
if( $prod_to_remove == $prod_id ) {
$WC->cart->set_quantity($cart_item_key,$cart_item['quantity'] -1,true);
break;
}
}
any insight over the issue is appreciated, thanks in advance
Link not clear in the comments but this is how the URL is being redirected
http://localhost/wordpress/index.php/cart/basket.php?r=1&id=2838023a778dfaecdc212708f721b788

woocommerce billing address form always appear even if the user is logged in?

I'm looking for a way to disappear woocommerce billing address in checkout page when the user is logged in. Is that possible? And in first place, Why is that?! Why billing address form is always showing in checkout page even when the user is logged in?!!!
1) For your question one try this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() ){
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
2) For your question two :
If user wants to modify something in billing form, this is the place where he can modify nothing else. If you think this is not correct, better to develop a plugin, maybe a lot of people will be thinking this.

Resources