Disable ajax add to cart button for specific product - php

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

Related

How to make [add_to_cart] button without shortcode with quantity field attached

This question comes in two parts:
Create a button that does the same as the woocommerce shortcode [add_to_cart] but without any plugins or shortcodes
Add a quantity field next to the add to cart button that allows the user to add a selected amount of products to their cart.
In essence, I want to circumnavigate the cart page, and have the customer add their product(s) on single pages.
So far, I am able to have a button that links the selected product to the cart page. The cart page is where a user is able to select the quantity of products to add, and add the products to the final checkout page. As stated above, I want to circumnavigate the cart page, and have the user be able to do the same functionality of the cart page, but on a regular page instead.
Here is my button that I have made for that purpose:
<form method="post">
<button class="Payment" name="asbestos_inspector_refresher">Register & Pay With Credit Card</button>
</form>
if(isset($_POST['asbestos_inspector_refresher']))
{
session_start();
$_SESSION['class_name'] = $class_name;
$_SESSION['product_name'] = $product_name;
wp_redirect("https://mwcti.com/Data_Table/?success=yes");
}
EDIT: Data_Table is a blank page before the cart page I made during testing to see if the value for the product would carry over to the cart page.

woocommerce, Hide those product on Website that are in cart

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.

Change main price when add to cart using opencart2.3

I have OpenCart v2.3 and I need make customize on product details page.
Explain what I need:
The product take price from the admin panel by default.
I need add custom price when user click add to cart button.
Explain how OpenCart adds product to cart:
When user click on add to cart button, ajaxFunction is called and goes to checkout/cart/add function with all input fields.
Inside function add() in cart controller
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
And system/library/cart/cart.php contains all functions
How can apply this idea?
"How can apply this idea?"
With difficulty, because it will affect a lot of parts of the system.
Perhaps you should consider having a second copy of the product with a different price and your code adjusts just the template so that clicking "Add to Cart" actually adds the second product instead.

WooCommerce: Add to Cart Button with Quantity - outside WooCommerce Loop

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'm looking to add a page of order meta before woocommerce cart page

I have set up a function on my billing/shipping page for woocommerce where the user selects a few items based on a custom loop.
I was wondering if it is possible to add a page before the cart page so process will be as follows:
Choose items from custom loop
press 'proceed to cart'(already hooked up to add the specific product)
press 'proceed to checkout'
On successful payment the information they chose on step 1 will show in their order on the backend and in the email.
I already have step 4 working but step 1 is actually on the checkout page. I need to move it to a page before the cart.
Is there a hook that I can use? Currently I am using
add_action( 'woocommerce_checkout_after_customer_details', 'my_custom_checkout_field' );
Thanks

Categories