I need help in finding the correct hook for WooCommerce. I'm trying to integrate design-builder API with the WooCommerce store. I have to make a redirect to the builder's website when a customer clicks "Add To Cart" on the product page. Example URL I need redirect to: https://exampleurl.com/designBuilder/{UniqueID} {UniqueID} is generated with this:
add_filter( 'woocommerce_add_cart_item_data', 'woo_api_add_cart_item_data', 10, 4 );
function woo_api_add_cart_item_data( $cart_item_data, $product_id, $variation_id, $quantity ) {
$product = wc_get_product( $product_id );
$unique_id = uniqid();
//...Some code...
return $cart_item_data;
}
Is there a WooCommerce hook to change the "add to cart" redirection URL and pass some values from the product?
CodePudding user response:
add_filter('woocommerce_add_to_cart_redirect', 'custom_woocommerce_add_to_cart_redirect', 10, 2);
function custom_woocommerce_add_to_cart_redirect($url, $product) {
$url = "https://exampleurl.com/designBuilder/{$product->get_id()} ";
header("Location: $url");
exit;
}
CodePudding user response:
add_action( "woocommerce_add_to_cart", "woo_api_test_func",10,6);
function woo_api_test_func($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data){
$redirect_url = $cart_item_data['clientDesignURL'];
wp_redirect( $redirect_url );
exit();
}
I've used this function. Redirection works However the product is not being added to cart :/