I am trying to create a custom cart page function which first goes through all the 'already added to cart items', but based on some conditions picks and populates the cart page with only some of those items. Now, the un-selected cart items, although not visible in the cart, are still preserved in the DB and will be pulled if another condition is met.
I have come across the filter woocommerce_cart_item_visible to 'hide' some cart items from the cart. It works as expected but just 'hides' the products while still adding their amount in the cart totals.
I could also try WC()->cart->remove_cart_item( $cart_item_key ); but it will remove the item from the DB too.
How can I achieve this?
Related
I'm trying to create a custom WooCommerce Cart. It would have the same capabilities as the real WooCommerce Cart. The only difference would be that in each cart, only specific types of products can go in.
Let's say I have a session variable that tells me which products to show. And based on that session variable, I add products to a specific cart. And you can always change that session variable but keep the products for each cart until the session ends.
After that, I go to the checkout and it will list items from the specific cart based on that session variable once again.
Is something like that possible, specifically having two separate WooCommerce carts, the default one and a new custom one?
I tried this:
if (! isset(WC()->cart_custom) || '' === WC()->cart_custom) {
WC()->cart_custom = new WC_Cart();
}
but every time I add products to the default cart and open the default cart page, the default cart is emptied. I don't know why.
I hope my question makes some sense.
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 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.
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.
I am new to prestashop
I want to show all the products in prestashop in my cart summary page.
Even though the customer doesn't ordered a product, it should be displayed in his/her shopping cart summary page with quantity as 0. So that from there he must be able to add quantity if he needs.
The product must be displayed category wise.
NB: I have searched and couldn't find a solution :-(
I think, you should not use cart, but should use template for product category instead of cart. This template make you able to show cart quantity. Cart will "invisible" in your shop. The user will select quantity of goods, all of them will add to the cart on 'onchange' event. When, the user press "Order" button and go to the real cart where he see the summary order information and confirm his order. Shop without traditional cart will inconvenient, because selected goods will in the different categories of the shop
The result will like this: http://screencast.com/t/8csYCudqD
Use ajax command which using on 'Add to cart' button click on 'onChange' event for input with good's count (simple jquery ajax)