Drupal Commerce order admin page, order id - drupal

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).

Related

Send selected order notification emails from admin list in Woocommerce

Would it be possible to add a custom bulk action to orders list in Woocommerce, which would allow for sending of order emails, based on the orders selected in the list? I have found very useful posts here (such as this), describing the procedure to make custom bulk actions, but I am missing the final piece of the puzzle - how to make that custom bulk action send out order notification emails.
I have looked through numerous plugins, but I haven't found anything related to my problem. Any help is appreciated.
Based on the link you supplied you will need to use wp_mail() function in the foreach loop.
This will send an email to each order in the loop.
Source: https://developer.wordpress.org/reference/functions/wp_mail/

WooCommerce admin order page - notify and list new orders when placed

I want to notify the admin whenever an order is being placed. I want the small icon which tell the number of orders to be incremented and the new order being listed on the order list. I do not know what action hooks and filter I can use to do such task!!!
I found the woocommerce_new_order action while I am searching here but I do not how can I create such visual effects using that action!
I expected to have the information that I can utilize to get the job done!

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

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

REST API woocommerce - Not showing all customers on GET/customers

Problem summary
I am trying to fetch all customers with POSTMAN using the latest woocommerce API (v3):
GET/customers
Yet only a small segment is returned. The number of customers returned is 28 (X-WP-Total) which is much less than the 150+ customers I have in the system.
Do you guys have any ideas on why only a subset of all customers are being returned instead of all? Does this have anything to do with how I configure woocommerce? Or am I just using the API incorrectly?
What i have tried
My goal is to create a small application to look up a customer by phone/email and then fetch the orders he had made.
Calling
GET/customers
Only returns a small subset of all customers and the rest is omitted.
Any customers omitted from the GET/customers will also return an empty array when i for example use
GET/customers?email=...
GET/customers?search=...
The requests returns an empty array on the omitted customers but
works on customers that was not omitted from:
GET/customers
Yet, given a known omitted customer ID, it is possible to look up that customer by sending a request to
GET/customer/{ID}
which does not make sense at all.
The solution is to set:
GET/customers?role=all
I figured that GET/customers only return by default customers whose role is 'customer'.
However, since I also make use of memberships/subscriptions, a customer would automatically get a new role assigned ('subscriber') whenever they opt-in for a membership. That customer would therefore not be included in the response since his role is no longer 'customer'.
Hope this helps anyone who stumbles upon the same problem.

WP: Best approach to to link a post to a person

I think this question is common, but I dont find a final solution.
Lets say I have a post type "event", what is the best approach to link a certain post to a certain person (speaker).
at the end i need a list of all speakers (alphabetical, according to their lastname) and of course the information of the speaker in a list of posts and single post view.
The speaker needs 4 data-fields: firstname, lastname, short-bio, weblink.
For a single event the amount of speker could be 1 ore many.
As far as I consider there a three different approaches to do this:
Custom fields
All needed custom fields are added directly to the cpt "events" using for example an acf repeater field.
the fields are blank textfields but a jquery ui script is providing an autocompleate feature with all values from the database (all firstnames, lastnames…)
Disadvantages from my perspektive: not so easy to query (especially when i have more than one speaker). The information about one certain speaker needed to give for every events.
Advantage: all information about a certain event, including the information about the speaker are editable on one page in the backend.
Posttype: "Speaker"
A second posttype named "speaker" will store all the infos about one speaker. An event could be related to one ore many speakers, for example by using the acf relationship field.
Disadvantages: all the information about the speaker are to be edit on another page in the backend. The user has first to create a speaker and second link this speaker to an event.
- question: is it possible, to include a second posttype into the backend of another posttype? For example by providing the possibility to create a new speaker inside the backend of the poststype "events"?
advantages: easy to query, easy to link a event to many speaker
Custom Taxonomy
I never tried this but maybe it is a good idea if possible.
The user can choose, add and edit a custom taxonomy providing all the informations (name, firstname, bio etc).
Is it possible to use more than one field for a custom taxonomy directly in the edit post view?
Maybe there is a final answer for this question?
I don't think their is a best approach, it depends on your need and your information architecture.
For example I may have a archive page of all speakers, so I can list all speakers and I can display the speaker's detail through the url http://mysite/speaker/ucheng. In this condition, I would prefer the post type solution.
Another Solution: Speaker User Role
What if you allow the speaker to edit their profile or upload some material for the event? If you want to do this, use default WordPress User and create a speaker role for it, so you can do some access control. Also, I can list the speakers on the frontend, and link the user to the event by using ACF.
For me, I would prefer the user role solution.

Resources