• Resolved gregorr64

    (@gregorr64)


    Hi,

    Is it possible to use custom fields (stored in my post) in my calculation? I used [CP_CALCULATED_FIELDS_VAR name=”myParam” from=”post”] but it doesn’t appear to be working.

    Any ideas?

    Thanks,
    Gregor

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @gregorr64,

    The shortcode [CP_CALCULATED_FIELDS_VAR] is used to generate global javascript variables with parameters that were passed to the page (by get or post) or session variables. In your case the variable myParam would be generated only if the page is being visited passing the parameter myParam by post.

    There are two possible solutions to your project.

    – If you are inserting the form’s shortcode into the page’s content, and you know the value of the custom field, simply pass it as another attribute in the form’s shortcode, it would be converted into a javascript variable with global scope that can be used in the equations as usual. In this hypothetical example:

    
    [CP_CALCULATED_FIELDS id="1" myparam="456"]
    

    Note that I’m passing the parameters in lowercase, WordPress always converts the names of attributes in the shortcodes to lowercase.

    Now you can implement in the form an equation similar to:

    fieldname1*myparam

    – Reading the custom field with the “DS” fields (The “DS” fields, is a set of fields distributed with the Developer and Platinum versions of the plugin, whose values are read from external data-sources, like a MySQL database or a CSV file).

    Assuming that myParam was stored as a metadata associated to the post:

    * Pass the post id as reference into the form’s shortcode: [CP_CALCULATED_FIELDS id="1" post_id="123"]

    * Insert a “Line Text DS” field in the form (or the DS field that corresponds to the datatype)

    * And enter as the query associated to the DS field:

    
    SELECT meta_value as value FROM {wpdb.postmeta} WHERE meta_key='myParam' AND post_id=<%post_id%>
    

    The DS field will contains the value of the custom field myParam corresponding to the post_id passed as attribute in the shortcode.

    Best regards.

    Thread Starter gregorr64

    (@gregorr64)

    Hi,
    Thanks for getting back to me, I’m still unsure which of the options would be best for my site.

    I’m looking to use custom fields (created with pods) in my products for price etc and use these along with user input to calculate the product price. I didn’t want to spent $99 on the dev option incase it didn’t work so I’m currently trying it out on a standard post.

    I’m going to be using the same formula on all of my products and need to bring in the custom field value for the respective product. These will then be used along with user input to calculate the product price.

    This means I don’t know the value of each custom field as it will change from product to product.

    How would I best get the value of the custom field?

    Thanks,
    Gregor

    Plugin Author codepeople

    (@codepeople)

    Hello @gregorr64,

    There is not a better or worst alternative. If you know the value of the custom field associated to the post, simply pass it as a new attribute in the form’s shortcode (As I described in the previous ticket). This solution is supported even for the free version of the plugin.

    Best regards.

    Thread Starter gregorr64

    (@gregorr64)

    Sorry, I should’ve explained better. I don’t know the values of the custom fields as the value will be different for each product that I have. And the “post_id” will be whichever product page that the user is on.

    I assume that with the woocommerce add-on I can use one form to calculate the prices of all of my products?

    Thanks,
    Gregor

    Plugin Author codepeople

    (@codepeople)

    Hello @gregorr64,

    If you are using the “CFF – WooCommerce” add-on to integrate the form with a WooCommerce product, and if the custom fields are stored as metadata associated to the product:

    * First, insert a calculated field in the form (I will call it fieldname1 in this steps descriptions), configured as hidden (thrpugh a checkbox in the field’s settings), with the following equation:

    jQuery('#woocommerce_cpcff_product').val()

    * Second, insert a DS field in the form with the following query:

    
    SELECT meta_value as value FROM {wpdb.postmeta} WHERE meta_key='myParam' AND post_id=<%fieldname1%>
    

    As you can see, now the product’s id and custom field are read at runtime.

    Best regards.

    Thread Starter gregorr64

    (@gregorr64)

    Hi @codepeople,

    Thanks for that, that appears to do exactly what I need it to.

    Quick question before I purchase the Developer option… How does the licensing work? Is it a one time payment or a yearly subscription? Also, how many sites is this for? I have a couple of sites that this plugin might be useful for.

    Thanks,
    Gregor

    Plugin Author codepeople

    (@codepeople)

    Hello @gregorr64,

    It is a one time purchase and can use the same copy of the plugin in all your websites (you simply should not distribute the plugin).

    Best regards.

    Thread Starter gregorr64

    (@gregorr64)

    Okay, that’s great thanks!

    Gregor

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Using Custom Fields in Calculation’ is closed to new replies.