Calculations Archives - Plugin Republic https://pluginrepublic.com/support-categories/calculations/ WooCommerce Plugins Sat, 30 Sep 2023 08:16:35 +0000 en-US hourly 1 https://pluginrepublic.com/wp-content/uploads/2020/10/cropped-favicon-1-32x32.png Calculations Archives - Plugin Republic https://pluginrepublic.com/support-categories/calculations/ 32 32 How to retrieve the page count of an uploaded PDF https://pluginrepublic.com/documentation/how-to-retrieve-the-page-count-of-an-uploaded-pdf/ https://pluginrepublic.com/documentation/how-to-retrieve-the-page-count-of-an-uploaded-pdf/#respond Tue, 25 Jul 2023 09:27:58 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=3496689 You can now access the page count for a PDF upload in your calculations by using this tag: {field_xxx_pdf_count} Note that you will need the Pro version of Add-Ons Ultimate and the Advanced Uploads extension to retrieve an uploaded PDF’s page count. The first step is to enable the feature by going to WooCommerce > […]

The post How to retrieve the page count of an uploaded PDF appeared first on Plugin Republic.

]]>
You can now access the page count for a PDF upload in your calculations by using this tag: {field_xxx_pdf_count}

Note that you will need the Pro version of Add-Ons Ultimate and the Advanced Uploads extension to retrieve an uploaded PDF’s page count.

The first step is to enable the feature by going to WooCommerce > Settings > Product Add-Ons > Uploads. Enable these settings and click ‘Save changes’.

  • Enable PDF uploads
  • Enable PDF page count

Then, create the following fields.

An Upload field which now accepts a PDF file. You will need to disable ‘Allow multiple uploads’ as the calculation will only read 1 file.

Create a Calculation field that will reference the Upload field. When a PDF file is uploaded, the calculation will retrieve the number of pages.

The post How to retrieve the page count of an uploaded PDF appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/how-to-retrieve-the-page-count-of-an-uploaded-pdf/feed/ 0
Add/show currency symbol on calculation fields in the cart https://pluginrepublic.com/documentation/add-show-currency-symbol-on-calculation-fields-in-the-cart/ https://pluginrepublic.com/documentation/add-show-currency-symbol-on-calculation-fields-in-the-cart/#respond Thu, 20 Jul 2023 13:26:43 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=3477784 By default, the calculation, and number field values don’t have a currency symbol in the cart/cart page. If you’d like the values to have your set currency symbol, then here’s a snippet you can use: Here’s how to add your snippet: How to add a code snippet to your site

The post Add/show currency symbol on calculation fields in the cart appeared first on Plugin Republic.

]]>
By default, the calculation, and number field values don’t have a currency symbol in the cart/cart page. If you’d like the values to have your set currency symbol, then here’s a snippet you can use:

View this code snippet on GitHub.

Here’s how to add your snippet: How to add a code snippet to your site

The post Add/show currency symbol on calculation fields in the cart appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/add-show-currency-symbol-on-calculation-fields-in-the-cart/feed/ 0
Using fractions in measurements https://pluginrepublic.com/documentation/using-fractions-in-measurements/ https://pluginrepublic.com/documentation/using-fractions-in-measurements/#respond Tue, 01 Nov 2022 07:38:39 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=2543363 You might want to allow users to enter measurements in fractions, most likely of inches. So a user might want to enter the width of an item as 5 and 1/8 inches. You can then use these measurements to calculate the price of a product. There’s an example product here showing this in action. To […]

The post Using fractions in measurements appeared first on Plugin Republic.

]]>
You might want to allow users to enter measurements in fractions, most likely of inches. So a user might want to enter the width of an item as 5 and 1/8 inches. You can then use these measurements to calculate the price of a product.

There’s an example product here showing this in action.

To allow the user to enter measurements in fractions:

  • First create a standard number field for your first dimension, e.g. ‘Width’, for the user to enter the whole number
WooCommerce number field
  • Then create a select field with the different fractions as the options – e.g. 1/8, 1/4, etc.
  • Enter the decimal equivalent of the fraction, e.g. 0.125, 0.25, etc, in the ‘Price’ column next to the fractions
  • Finally, set ‘Field Price Visibility’ and ‘Option Price Visibility’ to ‘Hidden’
WooCommerce field for fractions

You can repeat for any further dimensions – e.g. height.

Using fractions in calculations

You can now use the decimal values for the fields in your calculations. Create a calculation field to work out the value of your ‘width’ fields as a decimal:

Calculation field for fractions

Note that the formula looks like this:

{field_1752} + {field_1753_option_price}

You will need to change the field IDs to match yours. We use the {field_1753_option_price} tag to get the decimal value for the fractions.

You can also set this field to ‘Hide Calculation’ so that it’s not displayed on the front end. Also, ensure that you set the ‘Decimal Places’ to the create number.

Repeat this for your ‘height’ field.

Calculating the area

Now you can create a field to set the area. This will just multiply the value of your two calculation fields above.

The formula will be:

{field_2796} * {field_2797}

You will need to change the field IDs to match your own IDs.

The post Using fractions in measurements appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/using-fractions-in-measurements/feed/ 0
Zero value for missing fields https://pluginrepublic.com/documentation/zero-value-for-missing-fields/ https://pluginrepublic.com/documentation/zero-value-for-missing-fields/#respond Thu, 02 Sep 2021 14:05:54 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=1266431 If you include a tag in your calculation formula for a field that doesn’t exist on the page, the calculation will normally return an empty value. This means that if you have a formula like {field_123} + {field_456} you’ll only get a result if you have fields with the IDs 123 and 456 present on […]

The post Zero value for missing fields appeared first on Plugin Republic.

]]>
If you include a tag in your calculation formula for a field that doesn’t exist on the page, the calculation will normally return an empty value.

This means that if you have a formula like {field_123} + {field_456} you’ll only get a result if you have fields with the IDs 123 and 456 present on the page.

However, you might prefer the calculation to ignore a field if it’s not present and still return a value for those fields that are present. To enable this, go to WooCommerce > Settings > Product Add-Ons > Calculations and check the ‘Zero value for missing fields’ option.

The benefit of this option is that it allows you to create a single global calculation field which includes values for multiple fields, not all of which might be present on a single product.

The post Zero value for missing fields appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/zero-value-for-missing-fields/feed/ 0
Optimising calculations and conditions https://pluginrepublic.com/documentation/optimising-calculations-and-conditions/ https://pluginrepublic.com/documentation/optimising-calculations-and-conditions/#respond Wed, 28 Apr 2021 11:35:45 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=983144 If you have a large number of calculations or conditions, you might find that page performance is affected. If you find that the product page has slowed or is unresponsive, you can enable a couple of options. Go to WooCommerce > Settings > Products Add-Ons and enable: Note that these options are still in beta […]

The post Optimising calculations and conditions appeared first on Plugin Republic.

]]>
If you have a large number of calculations or conditions, you might find that page performance is affected. If you find that the product page has slowed or is unresponsive, you can enable a couple of options.

Go to WooCommerce > Settings > Products Add-Ons and enable:

  • Optimise calculations
  • Optimise conditions

Note that these options are still in beta so you should test your product page to ensure that it’s functioning correctly.

The post Optimising calculations and conditions appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/optimising-calculations-and-conditions/feed/ 0
Calculation fields https://pluginrepublic.com/documentation/calculation-fields/ https://pluginrepublic.com/documentation/calculation-fields/#respond Fri, 14 Jun 2019 07:38:07 +0000 https://pluginrepublic.com/?post_type=ht_kb&p=76780 Calculation fields allow you to make calculations using formulas. The formulas can include values inputted by the user through other fields, as well as fixed values, the product price, product properties like dimensions and weight, and other variables that you can set. There’s a video at the bottom of this page that will give you […]

The post Calculation fields appeared first on Plugin Republic.

]]>
Calculation fields allow you to make calculations using formulas. The formulas can include values inputted by the user through other fields, as well as fixed values, the product price, product properties like dimensions and weight, and other variables that you can set.

There’s a video at the bottom of this page that will give you an overview of the calculation field.

Calculation fields are available with the Pro version of the licence.

Creating a calculation field

Choose ‘Calculation’ as the field type. You can give the field a label if you wish.

In the ‘Formula’ field, enter the formula that will be used to make the calculation. You can use the following tags:

Field tags, e.g. {field_101}

In the image above, you can see that the formula contains the tag {field_960}. This means that the calculation will use the value from the field with the ID 960.

Note that when using field tags:

  • Fields must be in the same product
  • Fields can be either number fields or other calculation fields

Product price tags, {product_price}

You can include the product price in your formula, e.g.:

{field_960} + {product_price}

This will return the sum of the value of field ID 960 and the price of the product.

Global variables, e.g. {variable_1}

There is scope to set three global variables that can be used in your calculation fields. These are represented as {variable_1}, {variable_2} and {variable_3}.

You can set values for global variables from WooCommerce > Settings > Product Add-Ons.

Extending global variables

If the three global variables available to you aren’t enough, you can create as many unique variables as you like.

Set name / value pairs as in the snippet below:

View this code snippet on GitHub.

You can follow the steps here to add a snippet to your site.

Field price, e.g. {field_999_field_price}

To get the price value of a field, use:

{field_999_field_price}

Option price tags, e.g. {field_999_option_price}

You can get the value of selected options for radio and select fields, eg:

{field_999_option_price}

This will give you the value of the selected option for field 999.

Number of uploads

You can get the number of uploaded files by field, e.g:

{field_999_number_uploads}

This will return the number of files uploaded to field ID #999.

Pages in an uploaded PDF

Use the following tag to get the number of pages in an uploaded PDF:

{field_xxx_pdf_count}

See this article for a fuller explanation.

Quantity

You can get the value of the product quantity field to use in your calculation:

{quantity}

Look up tables

Look up tables allow you to pull prices from a pricing grid, based on user inputs. There is a dedicated article here on how to use them.

Dimensions and weight

Use the following tags in your formula for dimensions and weight:

{product_weight}
{product_length}
{product_width}
{product_height}

Attributes

If you have applied a single attribute term to your product that has a numerical value, you can use this in a calculation. For instance, if you have an attribute called ‘Pattern’ with the term ’10’ then you can pull this value into your calculations like this:

{pa_pattern}

Please note that this will only work when your attribute terms have numerical values; and it will only get the first term applied to the product.

Operators

You can use the following operators: +, -, *, /

You can use parentheses to determine the order of operations within the calculation.

For example:

( ( {field_950} * {field_951} ) + {product_price} ) / {variable_1}

You will need to ensure that your parentheses balance correctly otherwise the formula won’t evaluate.

Hide Calculation

Select this option to hide the calculation from the page, while still allowing it to function.

Rounding

You can choose to round up or round down to the nearest whole number. Just select the desired option from the ‘Round Result’ field.

Decimal Places

Set how many decimal places you’d like to return your result to.

Action

The ‘Action’ setting allows you to define how the calculation result might affect your product page.

  • Choose ‘Display As Cost’ if the calculation result will affect the cost of the product
  • Choose ‘Set Product Price’ to set the result of the calculation as the total product price
  • Choose ‘Update Quantity’ if the calculation result will change the quantity selected
  • Choose ‘Update Child Product Quantity’ to update the quantity field of a specific ‘Products’ field (radio images and radio list only). See this tutorial for more details
  • Choose ‘Add to Product Weight’ to add the result of the calculation to the weight of the product

Better Variations

If you are using the grid layout in Better Variations, you can get the total number of variations selected by the user with this:

{total_variations}

Bookings for WooCommerce

There are two parameters specifically for the Bookings for WooCommerce plugin:

{calculated_booking_cost} – this will return the total cost of the selected booking

{num_units_int} – this will return the number of selected units (e.g. days, weeks)

{num_bookings} – this will return the quantity selected

Advanced Custom Fields

If you are using the Advanced Calculations extension for Add-Ons Ultimate, you can include the value of fields created using ACF in your calculations.

To use ACF fields in your calculations:

  • Create your ACF fields for products. Only ‘Number’ fields will work with calculations
  • Any ACF fields on a product page will be automatically made available for calculations 
  • To use an ACF field in a calculation, you will need to use the ACF field name, e.g. my_number, prefix it with acf_, and wrap it in curly braces – e.g. {acf_my_number} – in your formula

Remember: you’ll need the Advanced Calculations extension to use ACF fields in calculations.

More information

There are several example products using calculation fields in this article.

You can also check out this video for an overview.

The post Calculation fields appeared first on Plugin Republic.

]]>
https://pluginrepublic.com/documentation/calculation-fields/feed/ 0