Bonsouir, I'm trying to redirect to checkout when a user add to cart a product just from the single product page, to be very specific from this page where everyone can see just the simple product
Now, everythings works just fine when I add this code to functions.php
function my_custom_add_to_cart_redirect( $url ) {
$url = wc_get_checkout_url();
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect','my_custom_add_to_cart_redirect');
But when i modify the code adding the condition to discriminate between the pages that are not the single product page with this code it doesnt work
function my_custom_add_to_cart_redirect( $url ) {
if ( is_product() ){
$url = wc_get_checkout_url();
return $url;
}
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
I put inside the condition an echo "it works"
and prints quite well but the redirect is not working.
Where do you think is the problem, this should works, is just an easy condition but dont work for me, Im using Avada Theme and Woocommerce updated
EDIT : It looks like when I add to cart, the links is generated as
[www.domain.com]/product/[name-of-product]/?add-to-cart=[PRODUCTID]
The path
[www.domain.com]/product/[name-of-product]/
IS considered for woocommmerce as product but the other one that includes ?add-to-cart=[PRODUCTID]
is not considered as product but it should be because it still is a product, is just sending a variable via GET
Do you know how to make recognize it as a product page ?
$url
inside the if statement?