I am new to Wordpress. I am developing store by using Woocommerce. When a product is added to cart then they must be hidden on the website for a specific time so that those products that are in the cart by any other user, not available on the website.
How can I do this?
I searched a lot but found nothing.
If you want to remove add to cart button from the products which are already in cart then you will need to check for the products' ID from the woocommerce cart session. and then use the filter hook woocommerce_is_purchasable.
add_filter('woocommerce_is_purchasable', 'coder_woocommerce_is_purchasable', 10, 2);
function coder_woocommerce_is_purchasable($is_purchasable, $product) {
return ($product->id == cart_session_product_id ? false : $is_purchasable);
}
In this way, you can hide the add to cart button.
If you want to hide the product itself then in woocommerce product loop in shop page, Just compare the product id from the woocommerce session cart and traverse the loop. If ID matches then skip that product. Customize this products loop of shop page in woocommerce theme template.
Related
I've have this issue with WooCommerce subscriptions where the AJAX Side cart causes the subscription switch to not function when a customer tries to switch from one subscription plan to another. Though this problem doesn't exist when the customer buys the subscription for the first time.
Only during subscription switch (perhaps during renewal too... I didn't check for renewal) does the AJAX effect cause the product to not be added to the cart. However, when I disable the side cart plugin AND the AJAX add to cart option in theme customization and redirect customer to cart page during checkout, everything works perfectly.
I thought I found a workaround for this by disabling the AJAX add to cart button for the "subscription" category so the mini cart doesn't open only for subscription products, using the following code below:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_default_button', 10, 2 );
function replace_default_button($button, $product){
//list category slugs where button needs to be changed
$selected_cats = array('subscription-category');
//get current category object
$current_cat = get_queried_object();
//get category slug from category object
$current_cat_slug = $current_cat->subscription-category;
//check if current category slug is in the selected category list
if( in_array($current_cat_slug, $selected_cats) ){
//replace default button code with custom code
$button = '<div class="add-to-cart-button">Buy now</div>';
}
return $button;
}
However, this is only meant for simple products and not for variable subscriptions. Is there a way to apply this code to variable subscriptions in a way such that AJAX is disabled only while switching the subscription plan, and keep it enabled during first time purchase?
Here's the link to the question where the code was originally posted as the solution:
Disable the ajax add to cart button woocommerce in specific categories
I am looking for the next solution in WooCommerce
Currently, when a customer clicks the product image on an archive page in WooCommerce, the single product page opens.
However, I would like to add the functionality that the product is immediately added to the shopping cart as opposed to opening the single product page
I don't know which code to apply but I tried with below code
add_filter ('woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_button_woocommerce');
I am new to wordpress, please let me know how the following can be done.
I am displaying woocommerce grouped product in a wordpress page via short code.
I have removed category title under product name via css
Is it possible to display the child products and add to cart button( instead of view products ) with the validation so that i don't have to go to product page
enter image description here
Thanks in advance
In addition to the WooCommerce product home page, I coded a second page template (with the wordpress page template function https://developer.wordpress.org/themes/template-files-section/page-templates/) that shows the woocommerce products in another schema.
... we call it „speed buy“, there is no informations about the products, just a list with title, price and the add to cart button.
My problem is, that we want to have not the normal add to cart button, but the add to cart button with quantity. Actually we call the add to cart button with
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
But this is the normal one without quantity.. any ideas?
Edit: We display the products on the page-template with a custom loop / WP_Query.
http://geecosme.nextmp.net/weaves/human-multiway-weave-135/human-multiway-weave.html
Its a configurable product.
here you could see that add to cart ('add to bag') button is there.
http://geecosme.nextmp.net/weaves/human-multiway-weave-135/human-multiway-weave-18-inches-darkest-black-120-grams.html
This is a simple product
In this simple product add to cart button is not showing. I have checked everything from quantity to availability and even reindexed data after setting manage to No. still nothing.
Its ajax based add to cart button.
Simple products that have a parent configurable product shouldn't be visible individually.
Magento will check if it has a stock on the simple product and will show it as an option in configurable.