-
Notifications
You must be signed in to change notification settings - Fork 12
/
cart unit prices.html
154 lines (84 loc) · 3.05 KB
/
cart unit prices.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!--
begin cart unit prices
License : < https://tinyurl.com/s872fb68 >
Version : 0.1d0
SS Versions : 7.1, 7.0
Dependencies : jQuery
twcsl
cart prices sqs-money-native add
Note : the code is comprised of several tags. all are needed for the
full effect to work
the effect is not active on mobile
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
-->
<style>
.twc-item-list-label--unit-price,
.twc-item-unit-price
{
display : none;
}
@media only screen and ( pointer : coarse ) and ( min-width : 1025px ),
screen and ( min-width : 800px ) {
.twc-item-list-label--unit-price {
display : inline-block;
font-size : 16px;
min-width : 10vw;
text-align : right;
vertical-align : middle;
white-space : nowrap;
}
.twc-item-unit-price {
display : inline-block;
font-size : 16px;
min-width : 10vw;
text-align : right;
vertical-align : middle;
white-space : nowrap;
}
.item-price, /* ._26eXSmpLx */
.XgjsO_M3Y /* price label */
{
min-width : 15vw;
}
}
</style>
<script>
$( ( ) => {
if ( ! twcsl.isCart ) return; // bail if not cart page
const getUnitPrice = $node => {
let price = $( '.item-price', $node )
.text ( )
.replace ( ',', '' );
let quantity = $( 'input', $node ).val ( );
price = Number ( price );
quantity = Number ( quantity );
let unitPrice = price / quantity;
unitPrice = unitPrice.toFixed ( 2 );
return unitPrice;
};
const setUnitPrice = node => {
const $node = $( node );
const unitPrice = getUnitPrice ( $node );
$( '.twc-item-unit-price :last', $node )
.text ( unitPrice );
}
$( `<div class="twc-item-list-label--unit-price">
<span class="_3zzV1fDFF">
<span>
UNIT PRICE
</span>
</span>
</div>` )
.insertBefore ( '.XgjsO_M3Y' );
$( '.item-price' )
.before ( `<div class="twc-item-unit-price" style="visibility: visible;">
<span class="sqs-money-native">
</span>
</div>` );
$( '.qrq0lfTEB' )
.each ( function ( ) {
setUnitPrice ( this );
} );
} );
</script>
<!-- end cart unit price -->