I think that I figured this out. In my functions.php file I had the below function to redirect to the checkout page when a product is added to the cart. So I captured the username variable there and then added it to the redirected URL:
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;
}
Curiously, neither get_query_var(‘username’) or $wp_query->query_vars[‘username’] worked. I’m not sure why.
Related Posts:
- Custom query filter not working on woocommerce category page
- Show recent products first but “sold out last” in query
- Query Nickname rather than Display Name in custom Woocommerce plugin
- Category_in return empty
- How i make a custom sql query for Woocommerce
- WooCommerce Total # orders [closed]
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- Reversing the order of posts AFTER the query is performed
- what are the numbers between curly brackets in search query
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Create pagination and order according to alphabet
- WooCommerce: Can’t use wc_get_products for custom REST API endpoints
- How to display Section for certain time
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- Remove [gallery] shortcode altogether
- query multiple taxonomy and show post count
- Categories and products in random order
- add_query_arg() XSS Vulnerability
- When add_query_arg() is necessary?
- Query multiple post type and categories
- Save default value for empty or missing post meta
- Listing posts by grouping dates
- Change searched term
- merge two query arguments into one WP_Query call
- Query Posts By Post Publish Date, but sort by Custom Meta Key
- How to export current year posts from WordPress?
- MySQL variable in query
- Style Post Differently In Query
- How do I see the mysql query generated by get_posts( $args )?
- is_search called incorreclty
- WordPress Query wp-terms SLOW
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Different values for get_author_posts_url and get_the_author (posts 2 posts)
- Problem when try to add ++1 for user meta
- query statement containing variable won’t execute
- Get posts from category with custom query
- get_users with array as meta_value
- How to display SQL query that ran in WC_Order_Query?
- Related post based on content
- Slow Search Queries – How to exclude pages, media, excerpt, authors, private posts?
- exclude pingbacks from wordpress SQL query
- How to interfere to default search to make it search in custom fields?
- WP_User_Query with more than two custom meta values
- Declaring a var, placing it in a query and using the output of the query?
- how do i register global query in template
- Combining two meta_values within one row with query
- Sort query_terms_list for post_tags alphabetically
- Target a page with query
- List only parent attributes on woocommerce admin atrributes page
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- How do I get specific readable results from this query and array results
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Add rewrite rule for archive search
- How to create a filter and add query params to all links
- How to fetch courses in all languages in WordPress?
- Get 2 meta values from meta key column
- WordPress add_query_arg from ajax and make url friendly
- My custom pagination not displaying
- Wpdb->last_query returns bad query
- How to get all images in Media Gallery with pagination?
- WP search exclude last letter from string
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Query reversed when I use “category__not_in”
- How to reduce the load / no of queries on MySql Database
- Performance of wp_get_attachment_image_srcset() and wp_get_attachment_image_url()
- Using the same WP_Query for shop and widgets in WooCommerce shop
- YearMonth datequery
- $query->set( ‘post_type’, ‘post’ ); not working
- Display result from custom post meta query
- Show certain number of post from tags
- Wpdb empty result only if language is Russian
- What is the best way to query posts based on live data?
- Include custom table in query
- How to fix this insert? Don’t work for me!
- Display Upload Author & Get Uploaded Post ID
- Display list of most recent grandchild (third tier) pages
- How can I display a number to represent the order of post?
- How to query custom post type one after another
- Update vs Insert logic but the last key is always inserted?
- Sort order in get_posts [closed]
- Query unique author ids with published post of type job
- Wpdb generates too many queries
- Custom Query for searching through custom fields
- Query posts alphabetically within this function
- Conditional Tag Custom Querys?
- Custom product loop avoiding duplicates
- List of buyers for each product
- query posts only works on the first page
- Custom Query for wp_posts using wp_postmeta
- WP Query outputs three items within a div
- How do I troubleshoot Maximum execution time of 60 seconds exceeded in updating a Media File?
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- update $wpdb one query
- Admin Post List table Query filtering “WHERE” for custom post type
- How to use a dynamic term id for the query block