Is it possible to pass a special query parameter value to a WooCommerce product link? - wordpress

I am looking to use WooCommerce in a bit of a strange way, and I'm wondering if there is any way to make this possible. Here's my desired workflow:
Step #1: From a different site subdomain, provide a link to a certain virtual product, but with a query parameter with a unique user id number.
Explanation: The user is at othersite.example.com, and they get a link to buy a product in a WooCommerce store set up with a wordpress site at https://example.com/product/virtual-product
However, this product will be a payment to unlock something on the othersite.example.com site which has its own user and authentication system. (Firebase)
Would it be possible to pass a user id from the othersite.example.com by way of a url query parameter and then have that included in the order info?
ie. From the othersite.example.com someone could be given a link to the product like this https://example.com/product/virtual-product?userid=00000000000000000, with 00000000000000000 being their user id at othersite.example.com.
Then if that userid query value could be included in the order, the following steps should be doable.
Step #2: Have a webhook that fires when the product is purchased, telling a server managing the users for othersite.example.com that the user with userid 00000000000000000 has made a successful purchase of that product.
Is there a way to accept custom values like this to the order? Or is this totally out of the scope of WooCommerce's functionality?
Thanks so much.

I believe that it can be done by using a redirection/link directly to the checkout page, like: "http://yourdomain.com/checkout/?add-to-cart=PRODUCTID&000000" (tested)
In the example, "checkout" stands for the name of your checkout page, "PRODUCTID" stands for the id of desired product, "000000" stands for the user id of redirected person in the other website.
Then you can add a hidden input field to the checkout page (into checkout form, so you will see this value in order) and using the URL you can assign the "000000" (user id) to the value of this field.
I hope that works. If you have any problems with implementation, you can ask me.
- Useful link for hidden input field addition: https://stackoverflow.com/a/42614905/11003615
- Useful link for getting value from current URL using JS: https://web-design-weekly.com/snippets/get-url-with-javascript/
- Useful link for getting value from current URL using PHP/Wordpress Core: https://wordpress.stackexchange.com/questions/274569/how-to-get-url-of-current-page-displayed
- Useful link (contains 4 parts) for adding a custom field to checkout & validating this field & saving this field to order fields & displaying the value of this field in order page: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-7

Related

I want to fetch submitted gravityform entries into another gravityform (wordpress)

Suppose I made form A and form B, I get a unique ID after submitting form A after that, another person opened form B and he entered just a unique ID given by me and enter additional information and submit it, then he might see the name and email ID that I entered in form A.
Please guide me to do this, also tell me if there is any form plugin or gravityform addon for this.
Now, in this case, I am trying to fetch submitted entries from form A to form B by using a unique ID that I created. (for unique ID I have a plugin so no worries about it)

Access Gravity Forms fields on previous page (before pre-submit)

Here's the sitch: I'm using a multi-page Gravity Form in conjunction with an external API.
On the first page of the form, the user supplies a phone number. On a subsequent page, I need to send the external API the phone number in order to retrieve the user's current settings, which then must be prepopulated in other fields.
I know how to use gform_post_paging, but since $entry hasn't been created yet I can't use it to pull fields from previous pages.
gform_pre_submission/gform_after_submission don't help me because I need to make the API call prior to users reaching the end of the form.
I've also tried handling this via jQuery, by pulling and storing the value of the phone field on page advancement (e.g. var phoneNum = jQuery('#input_2_25').attr('value');), but I get "undefined" no matter what when using field ids. (It works fine, in the same location, looking for other ids on the site, so the issue isn't with jQuery.) I'm guessing this means that between pages, the form elements don't exist in the view?
How can I accomplish this goal (i.e., retrieving a value from a previous page in a multi-page Gravity Form prior to the user reaching the end of the form)?
All of the data is stored in the $_POST variable on each page submission. Gravity Forms has a helper function for accessing $POST data. The format for the variable name will be 'input{fieldId}'.
$value = rgpost( 'input_1' ); // replace "1" with your field ID

Drupal Commerce order admin page, order id

I'm building a commerce site using Drupal Commerce. I've got it going very smoothly now but I've hit a dead end when I'm trying to create a module for handling shipping information and sending it to the shipping company for label printing.
The problem is, that I have created a new tab in an Order page,
admin/commerce/orders/order_id/printlabel
and I can access this page via a tab when I edit an order.
Now, I have no idea how I can pull the order_id number in the module. I have tried almost everything, entity_view, entity_metadata_wrapper, commerce_order.module API, but I have no idea how I can access the id and that is the key. When I get the ID, I can get the shipping information linked to it and I can send this data to the shipping company and save it.I also looked into the ways Commerce does things like combine Payment with Views but it seemed a bit too complicated for me to try so, I'm asking here. I can't get any answers on Drupal's own support forums.
Hope i got your question right.You created a custom menu admin/commerce/orders/*/printlabel where * is the order id of a particular order. You need the order id.
The simplest solution to it is getting it through the arguments or arg(). This is a function that drupal provides to get data from the arguments. For eg
if your url is www.xyz.com/admin/commerce/orders/0001/printlabel & you need order id i.e 0001 you can get it using arg(3).

MailChimp - Variable Content based on the FirstNames in the List

I have a list named "Students" of 500 members. Email will be sent to each member. Two things in the email content will be specific to each member. First one is:
Dear Michael
Michael will be replaced by each members First Name. Second is:
Click here
Click here will have a link behind redirecting each member to different target.
Followed this How to Create a campaign in MailChimp using ASP.Net
I am able to create a campaign using API, but I need to go further with or without API.
I've done this before for an email using personalisation. I didn't send it through MailChimp but I found this article that could help you: http://kb.mailchimp.com/article/getting-started-with-merge-tags/
In your list if you add a field for the student's first name and another field for the the link then you should be able to use merge tags to add that data to wherever you want it to be in your email.

Drupal Views Content Profile User as an argument

I have a normal Drupal User. I have used the content_profile module to create a profile content type. This content type contains a node reference to another content type company. The company node then references a type of node called Task.
I want to create a view that list all the tasks for a given user id.
So I imagine I would create a view with an argument of user id. Then I would add the relationship to the profile and the company and output the Task title.
The user id used seems to work on the created used ID and not the user id of the content profile that it is referencing. In our system the "admin" user creates the profiles so it causing some problems.
Any ideas? I feel I may need to write a custom module to do what I want.
i have answered a similar question in the past about how to create a view using part of the url as an argument to filter the view by the user profile. check out this url. the answer you are looking for may be a variation of my original response.
also, how are you creating those profiles? on one of my sites, when i created the profile page, its author ID is automatically changed to the user it is associated with.

Resources