mbr_math
Usage
This shortcode performs a calculation using the value stored in any contact field in your ActiveCampaign application. The result can be stored in any contact field in your ActiveCampaign application and also returned/displayed in WordPress.
Parameters
Parameters | Description |
---|---|
field | The name of an ActiveCampaign contact field to use as an operand. The field can be any contact field in ActiveCampaign. The available field names can be found in ActiveMember360, Utilities, Contact Fields. The lower case version of the Perstag should be used as the field name. Default: none. Required: yes. |
contact_id | The ActiveCampaign contact ID of the contact for whom the shortcode should be executed. Default: Current logged in user contact ID. Required: no. |
operation | The math operation to be performed. Permitted Values: add, sub (subtract), div (divide), mul (multiply), pow (power), mod (modulus), sqr (square root), max (maximum), min (minimum). Default: none. Required: no. |
value | The second operand for the math operation to be performed. This can be any value including that stored in the specified contact field in ActiveCampaign. The available field names can be found in ActiveMember360, Utilities, Contact Fields. The lower case version of the Perstag should be used as the field name.Default: none. Required: yes, except for sqrt (square root) |
target | The name of an ActiveCampaign contact field in which to save the result. The field can be any contact field in ActiveCampaign. The available field names can be found in ActiveMember360, Utilities, Contact Fields. The lower case version of the Perstag should be used as the field name. If set to the special value 'noupdate' no result will be stored. Default: field Required: no. |
round | The decimal rounding to apply to the result. If a positive value is provided the rounding will occur after the decimal point, if a negative value is provided the rounding will occur before the decimal point e.g -1 round to nearest ten. Halves are always rounded up. 0 means any value will be rounded to an integer Default: 0 Required: no. |
flip | Specifies whether the order of the operands should be switched. Permitted Values: 0, 1 Default: 0 (no) Required: no. |
show | Specifies if the result of the operation should be returned to WordPress for display or used within another shortcode. Permitted Values: 0, 1 Default: 1 (yes) Required: no. |
format | A sprintf-type format string to apply to the result of the operation. The format must follow the syntax rules set for PHP as detailed within sprintf. Example Values: %d formats as an integer, %.2f formats as a floating number with 2 decimal places. Default: none. Required: no. |
Validity
This shortcode is only processed for logged in users who also exist as contacts within ActiveCampaign.
In all other cases, including WordPress users with the Administrator role nothing will be processed.
Conditional Branching
This shortcode does NOT support conditional branching with [ELSE_math].
Nesting
Shortcode nesting within is NOT supported.
Examples
- Example 1
- Example 2
- Example 3
- Example 4
Returns the result of the calculation using the value stored in the field "fieldname1" with 300 added to it, storing the result back in the same field for the current logged in user:
[mbr_math field='fieldname1' operation='add' value='300' show='1']
Returns the result of the calculation using the value stored in the field "fieldname1" with 300 added to it, storing the result back in the same field for the contact whose contact id is stored in the contact field affiliate_id
of the current logged in user:
[mbr_contact contact_id='[mbr_db_affiliate_id]' field='fieldname1' operation='add' value='300' show='1']
Performs a calculation using the value stored in the field "fieldname1" divided by 2, storing the result back in the same field for the current logged in user:
[mbr_math field='fieldname1' operation='divide' value='2' show='0']
Performs a calculation using the value stored in the field "fieldname1" adding the value stored in the field "fieldname2". The result is rounded to two decimal places and stored as a floating number with 2 decimal places and is stored in the field "fieldname3" for the current logged in user:
[mbr_math field='fieldname1' operation='add' value='fieldname2' target='fieldname3' show='0' round='2' format='%.2f']
API
There is currently no ActiveMember360 API function equivalent for this shortcode.