/Shopify-Script-For-Discount-on-Prepaid-Order

Shopify Script For Discount on Prepaid Order & Increase Conversion

Primary LanguageJavaScript

Shopify-Script-For-Discount-on-Prepaid-Order

Shopify Script For Discount on Prepaid Order & Increase Conversion

There are certain types of tricks which can increase conversion on Shopify store and marchants can get good advantage from it. On of most popular and used worldwidely is Shopify Script For Discount applicable only on Prepaid Orders

In this section, I will explain you given below points.

  1. What is Shopify scripts?
  2. How to use Shopify scripts?
  3. How to implement these scripts? and related topics of Shopify scripts

Before proceediing next, I must like to clear that Shopify Scripts can be only used in Shopify Plus/ Gold Plans.

What is Shopify scripts?

Shopify scripts are written in Ruby which gave us permission to create new users experience. Using Line item, Shipping Method & Payment Methods scripts you can implement custom logic and tailor the user experience during a user’s checkout experience. Scripts are enabled on a store’s checkout by using the Script Editor app.

How to use Shopify scripts?

Use the Script Editor App to create, edit, test, and publish your scripts.

Only one script per script type can be published at one time. For example, you can publish a line items script and a shipping rates script, but you can't publish two line items scripts at the same time.

How to implement these scripts?

  • Open the Script Editor. The Scripts overview page shows a list of scripts for your store.
  • Click Create script to begin creating a new script.
  • Select script template.
  • In the Title box, enter a name for the script. Use a descriptive name so you can tell what the script does at a glance.
  • Click Code to open the Ruby source code console.
  • Click Run script to run the script.
  • click Save and publish to create and publish the script.

Given below steps you need to follow to implement Shopify script for prepaid order discount.

Major file to amendment

For changes on price according to discount based.
carrie.checkout-script.js

Shopify Ruby script code to apply discount on products.

lineitem_discount.rb
customer = Input.cart.customer
productIdArray = Array.new
qty = 0
discount = true;
Input.cart.line_items.each do |line_item|
  if line_item.properties['cod'] == 'cod'
    discount = false
  end
end

puts discount
if  discount
  Input.cart.line_items.each do |line_item|
   product = line_item.variant.product
   percent = Decimal.new(95) / 100.0;
   remaing_amount  = line_item.line_price * percent
   line_item.change_line_price(remaing_amount , message: "Free Shipping + Extra 5% OFF On Prepaid Orders.")
  end
end

Output.cart = Input.cart

Updated checkout.liquid to applicable for prepaid orders.

update_code_checkout.liquid