In Woocommerce single product pages, I've added a custom button using the woocommerce_after_add_to_cart
hook. The button will, when clicked/ pressed, re-directs the customer to the checkout.
But to avoid the customer clicking the button before having added the product to the cart, I added this: if ( WC()->cart->get_cart_contents_count() != 0 ) {
to the function.
My question is this: how can I have this button always available but inactive until a product is added to cart? How do I make it "grayed out" (not clickable) until there is a product in the cart?
Here is my complete code:
add_action('woocommerce_after_add_to_cart_button, 'instant_checkout');
function instant_checkout() {
$checkout_url = WC()->cart->get_checkout_url();
if ( WC()->cart->get_cart_contents_count() != 0 ) {
echo '<a href="'.$checkout_url.'" class="single_add_to_cart_button button alt">Instant Checkout</a>'; } }
Thanks for any help on this.