This is weird, but how can I only show the stock status on products that are virtual in the woocommerce store? Products not marked as virtual I want to hide the stock status.
Add the following code in your theme's function.php or in a plugin to display the stock only on products that are virtual and not on others.
add_filter("woocommerce_stock_html", "dont_display_stock_non_virtual");
function dont_display_stock_non_virtual($display, $availability){
global $product;
if( !$product->is_virtual() )
return "";
return $display;
}
P.S. - This code will not get affected if you update your WooCommerce.
Related
Objective:
I would like the customer to click on a button, add an item with quantity = 1 to cart, and route to checkout page automatically.
What I did:
I'm using Elementor to add a button with a href value of:
https://fakeurl.com/checkout/?add-to-cart=59
Problem:
Once I click the button, it will route to the checkout page, however it will add 2 quantity instead of one to the cart.
What I've tried:
Explicitly specify the quantity count in the href:
https://fakeurl.com/checkout?add-to-cart=59&quantity=1
But I'm getting the same results.
My checkout page is just simple page with 2 shortcodes namely woocommerce_cart & woocommerce_checkout:
Any idea why? Do I need to empty the cart before the aforementioned button is pressed?
Use your link structure as you already do > ?add-to-cart=59&quantity=1 and add below code in functions.php in your theme to just do checking
the only thing this peace of code do is to loop your cart to see if this product is already there .. and if it is - it sets $valid var on false
function is_product_in_cart( $valid, $product_id, $quantity) {
global $woocommerce;
if($woocommerce->cart->cart_contents_count == 0) return true;
foreach ( $woocommerce->cart->get_cart() as $key => $values ) {
$_product = $values['data'];
$id = $_product->id ;
if( $product_id == $id ) $valid = false;
}
return $valid;
}
add_filter( 'woocommerce_add_to_cart_validation', 'is_product_in_cart', 10, 3 );
Woocommerce default flow is that it will add the quantity to the cart whenever you add an item that is already in the cart.
Empty your cart whenever a new product is added to the cart so that only one remains in the cart.
In most cases the quantity is doubled because you are being redirected.
So the quantity is added and after the redirect the quantity is added again.
The reasons for this could be a couple of the things.
Theme or wordpress permalinks setting are adding or removing // in the links
Your checkout page is not set in woocommerce settings (woocommerce->advanced settings->Page settings)
How to check if you are being redirected (chrome)
At the top of Chrome's inspector (in the Network tab) is a checkbox which says Preserve log. Enable this option. Now it doesn't matter at all how the page navigates, the inspector will keep all log history -- including the redirect response.
(found here: See full redirect path and HTTP status code in Chrome)
Possible solutions
“Enable AJAX add to cart buttons on archives” (WooCommerce –> Settings –> Products -> General)
found here (https://www.businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/)
This sometimes help when having custom pages for cart and checkout.
Disable "Redirect to the cart page after successful addition" under WooCommerce > Settings > Products.Because you are linking to the checkout page, this wil redirect you again to the cart page.
I'm going crazy for a few hours, and I need help. Please :) I would like to disable the sale of products added by a specific seller in woocommerce. I use Dokan, a plugin that transforms woocommerce into a market place. This is what I did and that seems to me a good approach: I have created a new role "nonsellingshop" which has the same rights as the default seller role created by Dokan. This role can therefore add products and their price. I would like products added by this specific role can not be purchased, and instead of the add to cart button appears a message saying 'This seller does not offer its products for sale online'. Of course for the sellers not having this role, it is necessary that the sale is possible. It is also necessary that if I change the role of a seller "nonsellingshop" to give it the normal role, the sale becomes possible.
Does anyone have an idea of how I can do this?
Thank you a thousand times in advance for your help
So this what I've done so far (and that doesn't work) :
function get_seller_role_and_hide_cart_button_if_non_seller () { //gets the ID of the post $post_id = get_queried_object_id();
//gets the ID of the author using the ID of the post
$author_ID = get_post_field( 'post_author', $post_id );
//Gets all the data of the author, using the ID
$authorData = get_userdata( $author_ID );
//checks if the author has the role of 'subscriber'
if (in_array( 'boutiquenonvendeuse', $authorData->roles)){
add_filter( 'woocommerce_is_purchasable', '__return_false'); // DISABLING PURCHASE FUNCTIONALITY AND REMOVING ADD TO CART BUTTON FROM NORMAL PRODUCTS
remove_action('woocommerce_single_variation', 'woocommerce_single_variation', 10); // REMOVING PRICE FROM VARIATIONS
remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20); // REMOVING ADD TO CART BUTTON FROM VARIATIONS
}
} add_action ('init', 'get_seller_role_and_hide_cart_button_if_non_seller');
Basically, I finished building custom plugin for my client.
the only thing after products added to cart, before the checkout.
user able to change the quantity of the products, is it possible to display the selected quantity, but disabled the options to read only so client will able to see the quantity in cart page that he selected but can't change it?
and to apply this only to products that I used with my plugin either product ids or better category id because all the products there.
other product display and able to change quantity regular
by the way its regular products not virtual and not Sold Individually i need to find a way to limit clients to change quantity for some products only in cart page!, and not in product page.
I really appreciate any help.
As mentioned in the comment, you can use the woocommerce_cart_item_quantity filter for that. So that might look something like this:
function 668763_change_quantity_input( $product_quantity, $cart_item_key, $cart_item ) {
$product_id = $cart_item['product_id'];
// whatever logic you want to determine whether or not to alter the input
if ( $your_condition ) {
return '<h3>' . $item['quantity'] . '</h3>';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', '668763_change_quantity_input', 10, 3);
This would be just a simple example to replace the input with a h3 element containing the quantity. It can easily be adjust to alter the quantity input element to your liking.
i am new to woocommerce, actually i want to customize product display so i manually parse products from database i want to remove an item from woocommerce cart through product id, i have found this function,
$woocommerce->cart->get_remove_url($cart_item_key); in core woocommerce cart class, but i am unable to understand what i have to write in $cart_item_key, i have tried to product id or product url in it but its not removing product item from cart, can somebody help me please what i have write in this variable $cart_item_key,
/* Gets the url to remove an item from the cart.
*
* #return string url to page
*/
its description of that function, i have tried using full url of product page and also slug
Regards
Arsalan
I know its an old post but it may help someone.
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if($cart_item['product_id'] == $your_product_id)
$woocommerce->cart->get_remove_url($cart_item_key);
}
Hope its helps..
The default currency in the template based n woocomeerce that I am using is British pounds. The currency in the target country is different. Based on searching I found few ways of changing the currency. What is the best way?
http://www.kriesi.at/support/topic/change-of-the-woocommerce-price-currency
http://wcdocs.woothemes.com/snippets/add-a-custom-currency-symbol/
Furthermore, in which function.php file should the code be included? (one within wootemplate folder or within wp-includes directory)
Use any of the link mentioned in the above question. Add the code to functions.php of the theme. If using child theme, add it to the functions.php of child.
Here you can check this code:
add_filter('woocommerce_currency_symbol', 'change_currency_symbol', 10, 2);
function change_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'AUD': $currency_symbol = 'AUD $'; break;
}
return $currency_symbol;
}
If you want multi currency on your shop then try wordpress plugins for this functionality. but you must need to change settings from the woo-commerce end for checkout page & shipping cost calculation. plugins will switch currency at the shop but only few of them can able manage the same currency at cart & checkout page & while shipping cost calculation.