Change Woocommerce In Stock/Out Stock Text - woocommerce

I have seen examples on here where you add some text to the functions.php. However how would I change it from its current text which is
10 in stock to Only 10 left so that it keeps the quantity. And then when its sold out it says Sold Out

Here's a quick way to change the "Out of Stock" text to "Sold Out"
function so_28107321_availability( $availability, $product ){
if( $availability['class'] == 'out-of-stock' ){
$availability['availability'] = 'Sold Out';
}
return $availability;
}
add_filter( 'woocommerce_get_availability', 'so_28107321_availability', 10, 2 );
The "10 left" will automatically switch to "Only 10 left" if the stock quantity is below the woocommerce_notify_low_stock_amount option value. In your WooCommerce settings, you could set this value very high so that it would always say that.

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.

How to add dot with currency code in woocommerce plugin?

I want to add a dot with currency code, for example, my currency code is RS then I want this format (RS.) then the amount will be displayed.
I want this formate RS. 300 With my amount 300. kindly help me...
IN woocommerce I try many currency positions. for example in woocommerce they give us
left
right
left with space
right with space
But I also want "left with dot" and "right with dot".
how can I customize for this?
Is this not the decimal seperator? Maybe add this to . and then set the number of decimals to whatever you need
For This, You Must add a Custom Currency Symbol Try Adding bellow Code to your Functions.php in your child theme
/**
* Custom currency and currency symbol
*/
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['Rs.'] = __( 'Pakistani Rupees', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'Rs.': $currency_symbol = 'Rs.'; break;
}
return $currency_symbol;
}

Woocommerce product price duplicating

I want to add two prices on single product, first simple price was showing but when clicking on cariation size, price was duplicating, simple and variation both price showing, I want to show one price at a time.
Fix 2x price
GoTo: www.YOURDOMAIN/wp-admin/admin.php?page=wc-settings&tab=tax
then remove {price_excluding_tax} from "Price display suffix" input field
You Can try with jquery onchange function and get above product price and show at bottom
You can try to use this code. Hope it will work.
add_action( 'init', 'wp1232_remove_price_for_variations', 99 );
function wp1232_remove_price_for_variations() {
global $product;
if ( 'variable' == $product->get_type() ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
}
}

Woocommerce: only allow products from one tag per transaction

I have a WooCommerce site with the Responsive Supermarket Online Theme - Oswad installed. Each product has one of 4 tags corresponding to a different vendor. What I need to do when adding to cart:
Check the cart for products and get their tag.
If cart is empty, or the product tags match, allow adding to cart as per normal.
If the product has a different tag then that of the cart contents, disable the add to cart button.
Steps 1-3 should only occur once per transaction.
I know that I can check the tag with if ( has_term( 'tag', 'product_tag') ),
and in the add-to-cart.php, $product->isPurchasable() will toggle the visibility of the button.
My stumbling block is finding out how to put all these together to fulfill the requirement. I tried looking for how to restrict the cart items by categories but came up with dead ends. I looked for plugins but those restricted only the minimum/maximum product per order and not checking the category/tags of the items. I even tried to look at the hooks but ended up getting more confused.
Would appreciate it if I could get a pointer in the right direction.
One possible solution - at the add-to-cart.php:
global $woocommerce, $product;
$terms = wp_get_post_terms($product->id, 'product_tag');
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values){
$_product = $values["data"];
$_terms = wp_get_post_terms($_product->id, 'product_tag');
//echo "product slug: " . $terms[0]->slug;
//echo "cart slug: " . $_terms[0]->slug;
if ($terms[0]->slug !== $_terms[0]->slug){
//echo "NO MATCH";
$match = false;
}
}
and then add a if ($match) statement controlling the add to cart button: apply_filters('woocommerce_loop_add_to_cart_link', ...
Also, add the code to woocommerce/single-product/add-to-cart/simple.php and add the if statement to the location of the add to cart button.

Hide WooCommerce Add To Cart button when price is zero

I need to hide my add to cart button on the condition where the price = 0.00. If the price is greater than 0.00 i would like the button to reappear.
However i also use the WooTheme Wish List extension and i need the add to wish list button to remain. I would also like to change the text from Free to "Subscription Product" when the value is 0.00.
This is only needed on the single product page as we do not show the add to cart anywhere else.
Currently if the price is set to 0.00 i get the text at the top of the single product page saying "free" and the add to cart button remains as does the add to wish list button. If i remove the price all together the buttons also disappear hence why i need to "hide" the button to retain the wish list one.
I have tried the following Code inserted into my functions.php file
<?php
/*
* Swop the 'Free!' price notice and hide the cart with 'POA' in WooCommerce
*/
add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' );
function hide_free_price_notice( $price ) {
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 );
return 'POA';
}
?>
However, although it did work in that it changed the "Free" text to "POA" and also hid the "Add to Cart button" the "Add to Wishlist" button also disappeared.
If i changed the value to 0.01 everything appeared again so it nearly there... i just need the Wish List button to stay.
Any help or pointers would be greatly appreciated. Many Thanks...
Just for info, the reason i need to do this is because we run a subscription service, so products that are included in a subscription service do not need a price but do need to be shown so they can be added to a wish list. However sometimes we sell the products off so when they have a value i need the button to reappear so they can be added to the cart.
Simply having zero doesn't work because believe it or not people think they are free and try to add them to the cart to purchase !
Please add below code in your active theme functions.php and check it.
function wpcustom_is_purchasable( $purchasable, $product ){
if( $product->get_price() == 0 )
$purchasable = false;
return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'wpcustom_is_purchasable', 10, 2 );

Resources