Select Page
Edit on
Codepen.io

Automatically add product and start checkout on page load


x
55
 
1
<!--
2
Initialize the Store Builder Library
3
-->
4
<script
5
    id="fsc-api"
6
    src="https://sbl.onfastspring.com/sbl/1.0.2/fastspring-builder.min.js"
7
    type="text/javascript"
8
    data-storefront="fastspringexamples.test.onfastspring.com/popup-fastspringexamples"
9
    
10
    data-debug="true"   >
11
</script>
12
13
<script>
14
    //Fire once the page is loaded.
15
    document.addEventListener("DOMContentLoaded", function()
16
        {
17
            s =
18
            {
19
                //Reset the cart session  to remove everything added to the cart previously.
20
                'reset':true,
21
                //Define the product path(s) and the quantity to add.
22
                'products' : [
23
                    {
24
                        'path':'phot-io-main-app',
25
                        'quantity':1
26
                    },
27
                    //More than one product can be added at a time.
28
                    //{
29
                        //'path':'anotherproduct',
30
                        //'quantity':1
31
                    //}
32
                ],
33
                //Optionally apply a coupon
34
                'coupon':'FREE',
35
                //Optionally apply customer information to the order
36
                'paymentContact':{  
37
                    'email':'john@doe.com',
38
                    'firstName':'John', 
39
                    'lastName':'Doe', 
40
                    'company': 'Company Name', //optional
41
                    'phone': '555-555-5555', //optional
42
                    'addressLine1': '123 Main Street',  //optional
43
                    'addressLine2': 'Apartment 1',  //optional
44
                    'city': 'Lincoln',  //optional
45
                    'region': 'Nebraska',  //optional
46
                    'country': 'US',  //optional
47
                    'postalCode': '68510' //optional
48
                },
49
                //Specify that when this JSON object is pushed to the Store Builder Library to begin checkout process.
50
                'checkout':true
51
            }
52
            //Push the above JSON object to the Store Builder Library.
53
            fastspring.builder.push(s);
54
        });
55
</script>
1
 
1
1
 
1

Related Topics