Jump to content
thirty bees forum
  • 0

Solved: Pass Customization Field Data in URL to Product Page or Cart


Question

Posted (edited)

I run a WordPress website subscription service that is ordered through a Thirty Bees shop.  An email is sent 5 days before the end of the subscription reminding a customer to renew.  The email contains a direct link to the Thirty Bees product page for subscription renewal.  The subscription renewal in the Thirty Bees product page requires a customization field be filled in to enable the add to cart button.  I was wondering if it was possible to read the value of the customization field if it was passed in the url as a direct link to the product page in the shop, with the associated customization field filled in using the data in the url.  In an ideal world it would actually take the customer to a checkout page with the customization field populated.  The next best alternative would just open the product page with the customization field filled in already

Example - This is the product page url that opens the page with the single customization field:

https://crew-mgr.com/shop/home/3-annual-subscription-renewal.html

What I'd like to do:

URL formed with customization field data: https://crew-mgr.com/shop/home/3-annual-subscription-renewal.html?subdomain=subdomainnamehere

I can easily form the custom URL in the reminder email that gets sent to the customer.  On the Thirty Bees side I would like to know if there is a module or hook that would allow the url to be parsed for the custom field and the data to be automatically typed in the custom field on the product page.  

In WordPress I have a function to parse a URL whenever I want to grab parameters.  This could be easily modified with the customized field and used in Thirty Bees.  What I don't know is how this function would get triggered, and how to populate the custom field.  The URL parse function I use is below:

function cm_parseURL() {
	
	(isset($_GET['yr'])) ? $parsed_array['yr'] = $_GET['yr'] : $parsed_array['yr'] = NULL;

	(isset($_GET['canx']) && $_GET['canx'] == "true") ? $parsed_array['canx'] = TRUE : $parsed_array['canx'] = FALSE;
	
	(isset($_GET['data']) && $_GET['data'] == "true") ? $parsed_array['data'] = TRUE : $parsed_array['data'] = FALSE;
	
	(isset($_GET['tag_ids'])) ? $parsed_array['tag_ids'] = explode( ',', $_GET['tag_ids'] ) : $parsed_array['tag_ids'] = FALSE; // array of tag ids
	
	(isset($_GET['cat_ids'])) ? $parsed_array['cat_ids'] = explode( ',', $_GET['cat_ids'] ) : $parsed_array['cat_ids'] = FALSE; // array of cat ids

	(isset($_GET['expand']) && $_GET['expand'] == "true") ? $parsed_array['expand'] = TRUE : $parsed_array['expand'] = FALSE;
	
	(isset($_GET['from'])) ? $parsed_array['from'] = $_GET['from'] : $parsed_array['from'] = FALSE; // user id
	
	(isset($_GET['to'])) ? $parsed_array['to'] = $_GET['to'] : $parsed_array['to'] = FALSE; // ai1ec event id
	
	(isset($_GET['start'])) ? $parsed_array['start'] = $_GET['start'] : $parsed_array['start'] = FALSE; // ai1ec start unix time
	
	(isset($_GET['exp'])) ? $parsed_array['exp'] = TRUE : $parsed_array['exp'] = FALSE; // expanded date range passed from skipper clicking send email on event
	
return $parsed_array;
}
// end function cm_parseURL() to get current url and parameters to parse for use in setting query

 

Edited by Rhapsody
fixed typo, then marked as solved

3 answers to this question

Recommended Posts

  • 0
Posted (edited)

Thanks to @datakick the answer is fairly simple.  The customization field id is textField0 which was determined using the Chrome Inspect option.

The url for the product page has ?subdmn=desired_subdomain appended at the end where desired_subdomain is the text to be populated in the customized field box.

I used a Google search to get the correct Javascript syntax and inserted the script below on the Custom Code page in the section labeled Add extra JavaScript to your pages.

window.onload = function(){
    var subdmn = (new URLSearchParams(window.location.search)).get("subdmn");
    document.getElementById("textField0").value = subdmn;
};

 

This concept can be used for virtually any shop and product with customized fields.  Just change textField0 to whatever the ID is that matches the customized field you want to populate

Edited by Rhapsody
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...