​If you wish to apply limitations to the Woocommerce plugin, you will need to sign up for our Advanced Scripting subscription. It is free for the first 30 days and then $10 a month. You can read more about this here: https://support.partial.ly/advanced-scripting/

You can activate Advanced Scripting within your Partial.ly account under Settings > Advanced Scripting. Here is a direct link: https://partial.ly/merchant/merchant_script

Once activated, you will see a box to place the code needed for your limitations:

Below are examples of various scripts. We highly recommend you fully test any scripts you decide to use.

#1. Minimum order requirement:

total = context["total"]
if total < 300 then
   return {error="Partial.ly is not available for orders under $300"} 
else
    return true
end

Replace the amount with your preference.

#2. Different offers for different products

-- allowed product ids, anything else won't be allowed
allowed_products = {PRODUCT-ID-#1,PRODUCT-ID-#2}
-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false
 
    for _, value in ipairs(allowed_products) do
        if value == line.product_id then
           allowed = true
        end
    end
    if allowed == false then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end
-- map of product ids to offer ids, these are product ids with custom/non-default offers
custom_offers = {}
custom_offers[PRODUCT-ID-#1] = "OFFER-ID-#1"
custom_offers[PRODUCT-ID-#2] = "OFFER-ID-#2"
-- iterate over cart line items
for _, line in ipairs(context.line_items) do
    -- test if there's a custom offer for this line item
    if custom_offers[line.product_id] ~= nil then
        return {offer_id=custom_offers[line.product_id]}
    end
end
return true     

​Replace PRODUCT-ID-# and OFFER-ID-# with the required info.

​The product ID can be found within your Woocommerce admin.

The offer ID can be found in your Partial.ly account within the integration tool of your offer.

#3: Limit a specific product to a specific offer while having all other products default to the offer set within your Woo plugin

​-- iterate over cart line items
for _, line in ipairs(context.line_items) do
  -- test if product is in cart
  if line.product_id == PRODUCT-ID-# then
    return {offer_id="OFFER-ID-#"}
    else
        return true
  end
end

Replace PRODUCT-ID-# and OFFER-ID-# with the required info.

​The product ID can be found within your Woocommerce admin.

​The offer ID can be found in your Partial.ly account within the integration tool of your offer.

#4: Multiple Offers Limited by Price Range:

total = context["total"]

if total < 300 then
    return {error = "Partial.ly is not available for orders under $300"}
end

if total > 300 and total < 1000 then
    return {offer_id="OFFER-ID-#1"}
end

if total > 1001 and total < 3000 then
    return {offer_id="OFFER-ID-#2"}
end

if total > 3001 then
    return {offer_id="OFFER-ID-#3"}
end

Replace the amounts with your preference and the OFFER-ID-# with the required info.

​The offer ID can be found in your Partial.ly account within the integration tool of your offer.

#5: Combination: Limit a specific product to a specific offer while having all other products default to the offer set within your Woo plugin, plus a required price minimum.

total = context["total"]

if total < 300 then
    return {error = "Partial.ly is not available for orders under $300"}
end

-- iterate over cart line items
for _, line in ipairs(context.line_items) do
  -- test if product is in cart
  if line.product_id == PRODUCT-ID-# then
    return {offer_id="OFFER-ID-#"}
    else
        return true
  end
end

#6. Only have certain products available for offer set in plugin.

-- allowed product ids, anything else won't be allowed
allowed_products = {PRODUCT-ID-#1,PRODUCT-ID-#2}
-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false
 
    for _, value in ipairs(allowed_products) do
        if value == line.product_id then
           allowed = true
        end
    end
    if allowed == false then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end

#7. Limit products availability by product tag.

function contains(table, element)
    for _, value in pairs(table) do
        if value == element then
            return true
        end
    end
    return false
end

-- allowed product tags, anything else won't be allowed
allowed_tags = {"TAG-1", "TAG-2"}
-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false
 
    for _, tag in ipairs(allowed_tags) do
        if contains(line.tags, tag) then
           allowed = true
        end
    end
    
    if allowed == false then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end

return true

#8. Limit specific product tags to specific offers.

-- allowed product tags, anything else won't be allowed
allowed_tags = {"TAG-1", "TAG-2"}

-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false

    for _, tag in ipairs(allowed_tags) do
        for _, product_tag in ipairs(line.tags) do
            if tag == product_tag then
                allowed = true
                break
            end
        end
        if allowed then break end
    end

    if not allowed then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end


-- map of product tags to offer ids
custom_offers = {
    TAG-1 = "OFFER-ID-#1",
    TAG-2 = "OFFER-ID-#2"
}

-- iterate over cart line items for custom offers
for _, line in ipairs(context.line_items) do
    for _, tag in ipairs(line.tags) do
        if custom_offers[tag] ~= nil then
            return {offer_id = custom_offers[tag]}
        end
    end
end

return true

#9. Limit by category name.

-- allowed product category names, anything else won't be allowed
allowed_category_names = {"CATEGORY-NAME-1", "CATEGORY-NAME-2"}
-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false
 
    for _, category_name in ipairs(allowed_category_names) do
        for _, category in ipairs(line.categories) do
            if category.name == category_name then
                allowed = true
            end
        end
    end
    
    if allowed == false then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end

return true

#10. Limit specific categories to specific offers.

-- allowed product category names, anything else won't be allowed
allowed_categories = {"CATEGORY-NAME-1", "CATEGORY-NAME-2"}

-- check for any disallowed products
for _, line in ipairs(context.line_items) do
    local allowed = false

    for _, allowed_category in ipairs(allowed_categories) do
        for _, category in ipairs(line.categories) do
            if category.name == allowed_category then
                allowed = true
                break
            end
        end
        if allowed then break end
    end

    if not allowed then
        return {error="Can not use Partially with "..line.name.." in cart"}
    end
end


-- map of category names to offer ids
custom_offers = {
    ["CATEGORY-NAME-1"] = "OFFER-ID-#1",
    ["CATEGORY-NAME-2"] = "OFFER-ID-#2"
}

-- iterate over cart line items for custom offers
for _, line in ipairs(context.line_items) do
    for _, category in ipairs(line.categories) do
        if custom_offers[category.name] ~= nil then
            return {offer_id = custom_offers[category.name]}
        end
    end
end

return true

Don't see what you need?

Please reach out to our support team at support@partial.ly.