emmgunn
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Query String with WooCommerceYes. Now you’re making me nervous though. Do you see something questionable in my code?
Forum: Fixing WordPress
In reply to: Query String with WooCommerceI figured it out. I modified the redirect function like so:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); if ( ! empty( $_REQUEST['username'] ) ) { $thename = $_REQUEST['username']; $checkout_url = esc_url( add_query_arg('username', $thename, $checkout_url ) ); } return $checkout_url; }I’m not sure why $_REQUEST works, and the other methods I tried above do not??
Forum: Fixing WordPress
In reply to: Query String with WooCommerceThanks for the response. I gave this a try and the username field is still set to “defaultName”.
Looking into this some more, I think that there is some redirecting going on and so the “username=myname” is lost from the URL??? I’ve already got this code in the functions.php file to redirect straight to the checkout page when something is added to the cart:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }So I tried to use $thename = get_query_var( ‘username’, ‘defaultName’ ); in the above function thinking I could use add_query_arg() to add the username to the redirect, but $thename is still set to “defaultName”. I also tried your suggestion inside this function.
I’m guessing that the “add-to-cart=532” is handled somewhere earlier in the WooCommerce code and is doing some redirecting on its own. Perhaps that is where I need to read the username variable. I just don’t know how to find that in the code, and to be honest, I’m not sure how I would get that information to my custom_override_checkout_fields function in the functions.php file. Global variables?