Probably the most recurrent query we get about the use of the plugin for WooCommerce from APG WC - APG SMS Notifications is about how the custom variables are used. That is why today we have decided to write this little tutorial to explain the use of the custom variables in the plugin and to see whether its users, and the many who ask us the same question over and over again, understand their use in WC - APG SMS Notifications better that way.
When we talk about custom variables we are talking about the ability the plugin has to add to the SMS messages any kind of information contained in the order that is not natively accessible by the PHP code the plugin has.
Let us remember that the variables natively supported by the plugin are: %id%, %order_key%, %billing_first_name%, %billing_last_name%, %billing_company%, %billing_address_1%, %billing_address_2%, %billing_city%, %billing_postcode%, %billing_country%, %billing_state%, %billing_email%, %billing_phone%, %shipping_first_name%, %shipping_last_name%, %shipping_company%, %shipping_address_1%, %shipping_address_2%, %shipping_city%, %shipping_postcode%, %shipping_country%, %shipping_state%, %shipping_method%, %shipping_method_title%, %payment_method%, %payment_method_title%, %order_discount%, %cart_discount%, %order_tax%, %order_shipping%, %order_shipping_tax%, %order_total%, %status%, %prices_include_tax%, %tax_display_cart%, %display_totals_ex_tax%, %display_cart_ex_tax%, %order_date%, %modified_date%, %customer_message%, %customer_note%, %post_status%, %shop_name%, %order_product% and %note%.
It is worth remembering that the custom variables are added in the Custom variables text field of WC - APG SMS Notifications without including the % symbols before and after them.
Types of custom variables
To begin with, and to be as precise as possible, we must make it clear that there are two types of custom variables we can use in WC - APG SMS Notifications.
On the one hand there are variables that are not native to WooCommerce and that are not contained in the list of variables natively supported by the plugin, but that are easily accessible if you know their internal name.
A very specific example of this kind of variable that is accessible directly by the plugin would be the typical custom field in the billing and/or shipping form, which may have been created by ourselves or by some free or premium plugin for WooCommerce that we have installed in our online shop. For example our plugin for WooCommerce WC - APG NIF/CIF/NIE Field adds a NIF field in the billing form that is easily accessible by adding _billing_nif in the Custom variables field. The value of the _shipping_nif field of the shipping form can also be obtained by adding it in the same field.
On the other hand we have the ability to create a custom variable that is not directly accessible from the data contained in the order or that requires additional programming.
This kind of custom variable does not have to be added beforehand in the Custom variables field.
Preliminary notions
The first thing we have to bear in mind before tackling this tutorial is that we need to have solid knowledge of PHP and of the native WooCommerce functions.
If you lack either of the two things it is better that you do not waste your time and that you contact APG to ask for a quotation in keeping with your specific needs.
If you carry on reading this post it is because you have both abilities; congratulations.
Let us see how we can create custom variables in WC - APG SMS Notifications.
Our own custom variable
The best way to illustrate this tutorial is with a practical example where we are going to create a custom variable called order_product_completo. In our specific example we are only going to add one custom variable, but you can add as many custom variables as you need.
This example variable is going to make it possible for us to read all the attributes of a variable product. It is also very useful if you use the premium plugin Product Add-Ons, since it will read the content of all the form fields you have added to the product.
To be able to add one or several custom variables to the plugin from APG you only have to create a small PHP function in the functions.php file of your child theme or create a small plugin so as to be able to make use of it. It is important to point out that the PHP function has to make use of the custom filter of WC - APG SMS Notifications apg_sms_message. A completely functional example of the use of a custom variable is this one:
Where, whenever the variable %order_product_completo% is found in an SMS message, it will be replaced by something similar to this:
quantity x product name
attribute name: attribute
quantity x product name 2
attribute name: attribute
attribute name 2: attribute
…
As you can see, with the necessary knowledge it is very simple to be able to customise the SMS messages you send to your customers or to yourself by adding to them any kind of information contained in the order. Remember that if you lack the knowledge needed to do it, the best thing you can do is to contact APG to ask for a quotation that solves your needs.
We hope you find this tutorial useful and we look forward to your notes and comments, but remember before publishing that APG does not provide any kind of free support for its plugins.
Related posts
Comments







How to add Client Name with cusmtom message
%billing_first_name% %billing_last_name%, for example.
Remember that we don’t provide any kind of free support.
Kind regards.
Cordial Saludo,
Estoy probando el pluging y me ha parecido muy bueno y practico y me pregunto cual variable podria usar para agregar en el mensaje el nombre de la empresa transportadora y el numero de tracking,
Muchas gracias
Eso depende del nombre que le haya asignado a dichas variables tu plugin y de si son accesibles directamente o no.
Un saludo.
how can i add ewaybill number?
Ask to the third-party plugin author the name of variable or add your own PHP function to access it.
Kind regards.
How can i add the payment details depending on the payment method chosen?
You must create a custom function and use
$order->get_payment_method();.Best regards.
I am trying to include the appointment date into the SMS message sent to the client, how do I add this please?
Each plugin stores its metadata differently, you’ll have to figure out the metadata you want to read and make the corresponding custom code.
Best regards.