1

Right now I am using this function to redirect to the checkout page after adding a product to cart on my page with product grid:

function bbloomer_redirect_checkout_add_cart( $url ) {
$url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) );
return $url;
}

add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );

Instead of this I want the current page to reload with a parameter. For example

?addedtocart=productname. Is there any function or hook for it?

EDIT:

When editing the function to this:

function bbloomer_redirect_checkout_add_cart( $url ) {
$url = var_dump($url);
return $url;
}

add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );

The output is like this: string(0) "" string(41) "http://URL/winkelmand/"

PelHout
  • 83
  • 1
  • 12

1 Answers1

0

I think this should work:

function bbloomer_redirect_checkout_add_cart( $url ) {
   $param = $_REQUEST['add-to-cart'];
   $glue = (strpos($_SERVER['REQUEST_URI'], '?') !== false) ? '&' : '?';
   $url = $_SERVER['REQUEST_URI'].$glue.'addedtocart='.$param;
   return $url;
}

add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );
Shir Gans
  • 1,976
  • 3
  • 23
  • 40