im trying to put add to cart on content-product.php but without success.
I need a button that when the person clicks add to cart automatically.
I tried to put this:
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit" class="single_add_to_cart_button button alt"><?php echo $product->single_add_to_cart_text(); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
The button looks ok but dont add to cart...
Someone can help me?
Im using Woocommerce 2.1.5
Thanks so much
Adding:
do_action( 'woocommerce_after_shop_loop_item' );
to the content-product.php file should add the "Add to cart" button.
Related
I had added three buttons to the cart page, one for each payment method. Clicking on one of the buttons led to the checkout page where the corresponding payment method used to be pre-selected. It used to work, but somehow has stopped working after updating to the latest Woocommerce version. Any other way of doing this?
Here is the code in cart.php template for the buttons:
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with Purchase Order', 'woocommerce' ); ?>" />
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with PayPal', 'woocommerce' ); ?>" />
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with Credit Card', 'woocommerce' ); ?>" />
<?php /*do_action( 'woocommerce_proceed_to_checkout' );*/ ?>
<?php wp_nonce_field( 'woocommerce-cart' ); ?>
</form>
I was wondering if there is any chance to change the radio button into a normal button like the one that says "Ask Question" on the Stack Overflow main page.
I'm using woocommerce with deposit - partial payment plugin. The plugin has 2 options, some kind of bar with DEPOSIT and FULL PAYMENT option and the second with radio buttons for the same options.
<?php _e( $deposit_option_text, 'woocommerce-deposits' ); ?>
<span id='deposit-amount'><?php echo $deposit_amount; ?></span>
<span id='deposit-suffix'><?php echo $suffix; ?></span><br><br>
</label>
<div class="<?php echo $basic_buttons ? 'basic-switch-woocommerce-deposits' : 'deposit-options switch-toggle switch-candy switch-woocommerce-deposits'; ?>">
<input id='pay-deposit' name='<?php echo $product->get_id(); ?>-deposit-radio'
type='radio' <?php checked($default_checked ,'deposit'); ?> class='input-radio' value='deposit'>
<label id="pay-deposit-label" for='pay-deposit'
onclick=''><?php _e( $deposit_text , 'woocommerce-deposits' ); ?></label>
<?php if( isset( $force_deposit ) && $force_deposit === 'yes' ){ ?>
<input id='pay-full-amount' name='<?php echo $product->get_id(); ?>-deposit-radio' type='radio'
class='input-radio'
disabled>
<label id="pay-full-amount-label" for='pay-full-amount'
onclick=''><?php _e( $full_text , 'woocommerce-deposits' ); ?></label>
<?php } else{ ?>
<input id='pay-full-amount' name='<?php echo $product->get_id(); ?>-deposit-radio'
type='radio' <?php checked($default_checked ,'full'); ?> class='input-radio' value='full'>
<label id="pay-full-amount-label" for='pay-full-amount'
onclick=''><?php _e( $full_text , 'woocommerce-deposits' ); ?></label>
<?php } ?>
Any idea how to change the 2 radio buttons into regular buttons?
I've had a problem on the checkout of my site's page for a while whereby the Update Cart button is not working. If you go into the element where the quantity of the item is, and change the amount from (for example) 4 to 2 and press enter then it updates, but if you change the quantity and press Update Cart, nothing happens. This is the code for the button in my FTP, and I'm just not seeing the problem:
<button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); ?></button>
Inspecting the element in Google I notice it is down as being disabled, but I don't know where to enable it in the FTP:
<button type="submit" class="button" name="update_cart" value="Update cart" disabled="">Update cart</button>
EDIT: Moved comment into question
Though looking at the Coupon section of the Checkout, I'm wondering if the Update Cart button should look more like this:
<div class="coupon">
<label for="coupon_code">
<?php esc_html_e( 'Coupon:', 'woocommerce' ); ?>
</label>
<input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" />
<input type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>" />
<?php do_action( 'woocommerce_cart_coupon' ); ?>
</div>
<?php } ?>
EDIT2: I found a temporary solution by going to:
wp-content/plugins/woocommerce/assets/js/frontend/cart.min.js
searching for:
.prop("disabled",!0)},input_changed
and changing the !0 into a !1
This works for the first update to the cart, then it goes back to not working again, but it's a start.
try replacing the
<button name="update_cart">
with an input instead
<input type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>">
Had the same problem when updating woocommerce and noticed they changed some of their inputs into buttons instead, so just revert back to using inputs for problem areas.
I created a custom checkout page.
I wanted to put the coupon code anywhere and it worked.
Unfortunately after clicking on the "apply coupon" button, instead of validating the coupon and adding it to the order, the system responds as per clicking the "order and pay" button Code used in form-checkout.php:
<?php do_action('woocommerce_checkout_coupon_form', $checkout); ?>
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
<div class="checkout-form-container">
<?php if ( sizeof( $checkout->checkout_fields ) > 0 ) : ?>
<?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
<div class="col2-set" id="customer_details">
<div class="col-1">
<?php do_action( 'woocommerce_checkout_billing' ); ?>
</div>
</div>
<?php do_action( 'woocommerce_checkout_after_customer_details'); ?>
<p class="form-row form-row-first">
<label for="coupon_code">Coupon?</label>
<input type="text" name="coupon_code" class="custom-coupon-code-input input-text" placeholder="<?php esc_attr_e( 'Wprowadż kod', 'woocommerce' ); ?>" id="coupon_code" value="" />
</p>
<p class="form-row form-row-last">
<input type="submit"button class="button custom-apply-coupon-btn">
<?php esc_attr_e( 'Apply', 'woocommerce' ); ?>
</button>
</p>
<?php endif; ?>
</div>
Check your checkout page HTML. You are actually putting your coupon form inside checkout form. HTML forms doesn't support nested forms.
Put the form outside of checkout form. If you really need to show them there then take those values by javascript with the click of 'Apply Coupon' button and do the validation. But A form tag inside another form is not the correct way.
The submit button is submitting parent form also. That's why you are getting that.
I know where is the problem. Everything works perfectly on woo 2.6.8 but after update to min 3.0.4 its crash as I described above.
I'd like to give another html element the function of 'add to cart'. Is this possible? I have added some html code into single-product.php and want one of these elements to function as 'add to cart' when you click on them :)
I hope that I've been able to explain myself :P
The following will work as an add to cart button within a product loop, where $product is the post object -
<?php if( $product->is_purchasable() ):?>
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit">Add to Cart</button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
<?php endif; ?>