Using the product attribute values into the formula?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #99096
    Zack
    Guest

    Hi Tom, I am really interested in buying your plugin. However, am I able to use your plugin with variable product attributes and using the attribute values into the formula? For example, I have a custom product attribute called “Number Of Prints” that is used for variations; Can I use it as part of the formula?

    #99097
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Zack,

    Please try:

    [product_meta key="attribute_pa_number-of-prints"]
    #99098
    Zack
    Guest

    Thank you so much for your reply Tom! Can I ask another question? What if my attribute is of a text value instead of an integer value? Can I still use the conditional if_value shortcode?

    #99099
    Zack
    Guest

    For example:
    [if_value value=”{product_meta key=’attribute_pa_media-type’}” compare_operator=”equal” compare_to_value=”paper”]x*4.9[/if_value]

    #99100
    Tom Anbinder
    Moderator
    Plugin Support

    Wasn’t possible (as [product_meta] shortcode automatically converted the value to number), however, I have just added new convert_to_numeric shortcode attribute to [product_meta] in our development version, so now you should use:

    [if_value value="{product_meta key='attribute_pa_media-type' convert_to_numeric='no'}" compare_operator="equal" compare_to_value="paper"]x*4.9[/if_value]
    #99101
    Zack
    Guest

    Wow! This is amazing. Great work man. However, can I confirm if this plugin will work with variable product?

    For example, my variable product have 2 options (attributes).
    1: Media Type (Paper, Cardboard)
    2: Number Of Prints (1, 2, 3)

    Formula:
    [if_value value=”{product_meta key=’attribute_pa_media-type’ convert_to_numeric=’no’}” compare_operator=”equal” compare_to_value=”paper”]
    (x+0.2)*{product_meta key=’attribute_pa_media-type’}
    [/if_value]
    [if_value value=”{product_meta key=’attribute_pa_media-type’ convert_to_numeric=’no’}” compare_operator=”equal” compare_to_value=”cardboard”]
    (x+0.5)*{product_meta key=’attribute_pa_media-type’}
    [/if_value]

    So when I select my options in the frontend, the pricing will update as accordingly?

    #99102
    Tom Anbinder
    Moderator
    Plugin Support

    Yes, it will work with variable products (i.e. will set different prices for each variation depending on variation’s attributes). Small fix in formula is needed though:

    [if_value value="{product_meta key='attribute_pa_media-type' convert_to_numeric='no'}" compare_operator="equal" compare_to_value="paper"]
    	(x+0.2)*[product_meta key="attribute_pa_number-of-prints"]
    [/if_value]
    [if_value value="{product_meta key='attribute_pa_media-type' convert_to_numeric='no'}" compare_operator="equal" compare_to_value="cardboard"]
    	(x+0.5)*[product_meta key="attribute_pa_number-of-prints"]
    [/if_value]

    I.e. { and } brackets are only used inside shortcodes attributes, and inside shortcode’s content you need to use normal (i.e. square) brackets ([ and ]) for shortcodes.

    #99103
    Zack
    Guest

    AWESOME! Is there anyway I can try a demo of the frontend first? I can’t seem to find any demo websites here.

    #99104
    Tom Anbinder
    Moderator
    Plugin Support

    If anyone else has similar tasks – we’ve just released new plugin v2.2.1, where we have:

    1. added [product_attr] shortcode, which would be the correct way of retrieving the product’s attributes, e.g.:

    [product_attr attribute="number-of-prints"]

    You can also get product attribute’s value as suggested earlier by:

    [product_meta key="attribute_pa_number-of-prints"]

    However it seems that this way only works for variations, but not for simple type product’s attributes, while [product_attr] shortcode works for all types of products.

    2. added convert_to_numeric attribute to the [product_meta] shortcode (attribute defaults to yes).

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Product Price by Formula for WooCommerce’ is closed to new topics and replies.