Custom Hooks (technical knowledge required)

⚠️  Note that this is a technical explanation intended for website builders.

For our (Parcel Pro) plugin, we also have the ability to overwrite certain values via external code before sending them to our server. This is useful if you have a separate implementation of the checkout in which standard fields from WooCommerce are modified. A common example of this is the field address_1 which is often split into separate fields: street name and house number. If this data is forwarded, the house numbers often do not come in correctly

Below we show how to modify this with our custom hook in the WooCommerce code.

1 Function

The first step is to create an independent function. That means a function outside the scope of a class so that it can be easily found by the WooCommerce system during the call.
//A function that is not in the scope of class to add to the custom hook.

This function will receive the value $data. This will be padded with the complete shipping data sent to the Parcel Pro system. Below is the json representation of this data.
In this example, we take the value shipping_address and from it the field address_1 and overwrite it with our new value, street name and house number stuck together. In this case we chose Griede and 22 for this, you could replace these with variables.

JSON $data

{
   "orderNR":"421",

   "increment_id":421,

   "order":{

   },

   "items":[

      {

         "id":135,

         "order_id":421,

         "name":"Product 7"

         "product_id":15,

         "variation_id":0,

         "quantity":2,

         "tax_class":"",

         "subtotal":"0",

         "subtotal_tax":"0",

         "total":"0",

         "total_tax":"0",

         "taxes":{

            "total":[

            ],

            "subtotal":[

            ]

         },

         "meta_data":[

         ],

         "sku":""

      }

   ],

   "billing_address":{

       "firstname":"ICT",

      "lastname":"Parcel Pro",

      "company":"",

      "address_1":"Griede 22",

      "address_2":"",

      "city":"hoogvliet",

      "state":"",

      "postcode":"3191 EE",

      "country_id":"NL",

      "email":" ict @parcelpro.nl",

      "telephone":""

   },

   "shipping_address":{

      "firstname":"ICT",

      "lastname":"Parcel Pro",

      "company":"",

      "address_1":"Griede 22",

      "address_2":"",

      "city":"hoogvliet",

      "state":"",

      "postcode":"3191 EE",

      "country_id":"NL",

      "email":"[email protected]",

      "telephone":""

   },

   "subtotal":0,

   "subtotal_incl_tax":0,

   "grand_total":"0.00",

   "shipping_method":"parcelpro_maatwerk_5_0",

   "created_at":{

      "date":"2020-03-24 14:10:27.000000",

      "timezone_type":1,

      "timezone":"+00:00"

   },

   "aantal_pakketten":1

}

2 Add_action

To ensure that this function is called, we need to add an action for our hook parcelpro_format_order_data for this purpose. You can do that using the following line:
'add_action(' parcelpro_format_order_data','independent_function_to_process_data');
After this modification, the previously created function is called and the data is modified. Then this is sent to the Parcel Pro shipping system, now with the correct value of your custom check out!

Frequently Asked Questions 

With a WooCommerce shop, can you also show DHL and/or PostNL parcel points in the checkout?
Yes you can set the option DHL Parcelshop or PostNL Parcelshop in the WooCommerce plugin to show all points. This way, customers who order can choose a pickup point themselves.
Is it also possible to create multiple WooCommerce links?
Yes this is possible as long as there is a separate back-end environment for each link. You can then install the link in the new back-end in exactly the same way.

An order transfer using the button does not work.
Check if your UserID and API  Key data are correct in the plugin's configuration. These can be found via WooCommerce > Settings > Shipping Methods > Parcel Pro. And in the shipping system on the Links page.

Which carriers are supported?
The carriers  BrengerBudbeeDHLFedex Cross BorderHomerrPostNLSave your Package and  UPS are supported based on the activated contracts under your account in the shipping system.
The track & trace button shows a blank page
For best performance, we recommend using the shipping methods from our plugin. This way a consumer can choose a linked shipping method. When the data is transferred, the shipping system can determine a corresponding shipping type and immediately feed back the required track & trace data. If not, it will be based on the default shipping method set in the shipping system.
If our shipping methods are not used in the plugin, all shipments will be entered into our shipping system based on the default shipping type. This can therefore mean that an incorrect track & trace code is fed back to WooCommerce. In this case, it is useful to uncheck the checkbox Add tracking to order.

A shipment contains incorrect data or an incorrect type of shipment
This has to be changed manually in our shipping system. For the time being, it is not possible - after an order with chosen shipping type from the consumer - to make a change to the shipping type in WooCommerce, or to resubmit an order.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.