No add to cart redirect, and use POST for add-to-cart Closes #3200

This commit is contained in:
Mike Jolley 2013-06-14 12:48:41 +01:00
parent e1b49eb783
commit b38ef8efcd
4 changed files with 15 additions and 18 deletions

View File

@ -30,7 +30,7 @@ foreach ( $product->get_children() as $child_id ) {
<?php do_action('woocommerce_before_add_to_cart_form'); ?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<form class="cart" method="post" enctype='multipart/form-data'>
<table cellspacing="0" class="group_table">
<tbody>
<?php foreach ( $grouped_products as $child_product ) : ?>
@ -70,6 +70,8 @@ foreach ( $product->get_children() as $child_id ) {
</tbody>
</table>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<?php if ( $quantites_required ) : ?>
<?php do_action('woocommerce_before_add_to_cart_button'); ?>
@ -79,7 +81,6 @@ foreach ( $product->get_children() as $child_id ) {
<?php do_action('woocommerce_after_add_to_cart_button'); ?>
<?php endif; ?>
</form>
<?php do_action('woocommerce_after_add_to_cart_form'); ?>

View File

@ -27,8 +27,7 @@ if ( ! $product->is_purchasable() ) return;
<?php do_action('woocommerce_before_add_to_cart_form'); ?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action('woocommerce_before_add_to_cart_button'); ?>
<?php
@ -39,10 +38,11 @@ if ( ! $product->is_purchasable() ) return;
) );
?>
<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 apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
<?php do_action('woocommerce_after_add_to_cart_button'); ?>
</form>
<?php do_action('woocommerce_after_add_to_cart_form'); ?>

View File

@ -14,7 +14,7 @@ global $woocommerce, $product, $post;
<?php do_action('woocommerce_before_add_to_cart_form'); ?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo $post->ID; ?>" data-product_variations="<?php echo esc_attr( json_encode( $available_variations ) ) ?>">
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo $post->ID; ?>" data-product_variations="<?php echo esc_attr( json_encode( $available_variations ) ) ?>">
<table class="variations" cellspacing="0">
<tbody>
<?php $loop = 0; foreach ( $attributes as $name => $options ) : $loop++; ?>
@ -83,7 +83,10 @@ global $woocommerce, $product, $post;
<button type="submit" class="single_add_to_cart_button button alt"><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
</div>
</div>
<div><input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" /></div>
<div>
<input type="hidden" name="add-to-cart" value="<?php echo $product->id; ?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
</div>
<?php do_action('woocommerce_after_add_to_cart_button'); ?>

View File

@ -282,7 +282,6 @@ function woocommerce_update_cart_action() {
* @return void
*/
function woocommerce_add_to_cart_action( $url = false ) {
if ( empty( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) )
return;
@ -426,8 +425,8 @@ function woocommerce_add_to_cart_action( $url = false ) {
}
// If we added the product to the cart we can now do a redirect, otherwise just continue loading the page to show errors
if ( $was_added_to_cart ) {
// If we added the product to the cart we can now optionally do a redirect.
if ( $was_added_to_cart && wc_error_count() == 0 ) {
$url = apply_filters( 'add_to_cart_redirect', $url );
@ -438,17 +437,11 @@ function woocommerce_add_to_cart_action( $url = false ) {
}
// Redirect to cart option
elseif ( get_option('woocommerce_cart_redirect_after_add') == 'yes' && wc_error_count() == 0 ) {
elseif ( get_option('woocommerce_cart_redirect_after_add') == 'yes' ) {
wp_safe_redirect( $woocommerce->cart->get_cart_url() );
exit;
}
// Redirect to page without querystring args
elseif ( wp_get_referer() ) {
wp_safe_redirect( add_query_arg( 'added-to-cart', implode( ',', $added_to_cart ), remove_query_arg( array( 'add-to-cart', 'quantity', 'product_id' ), wp_get_referer() ) ) );
exit;
}
}
}