PluginProbe
Additional Terms Lite for WooCommerce / 1.7.3
Additional Terms Lite for WooCommerce v1.7.3
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / assets / js / block.js

block.js in Additional Terms Lite for WooCommerce 1.7.3, at assets/js/block.js

134 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function ( wp, wc ) {
2 'use strict';
3
4 if ( ! wp || ! wc ) {
5 return;
6 }
7
8 const el = wp.element.createElement;
9 const { registerBlockType } = wp.blocks;
10 const { InspectorControls, useBlockProps } = wp.blockEditor;
11 const { Disabled, ExternalLink, Notice } = wp.components;
12 const { SVG, Path } = wp.primitives;
13 const { CheckboxControl } = wc.blocksCheckout;
14 const { ADMIN_URL, getSetting } = wc.wcSettings;
15 const { __ } = wp.i18n;
16 const settingsUrl = `${ ADMIN_URL }admin.php?page=wc-settings&tab=woo-additional-terms`;
17
18 registerBlockType( 'mypreview/woo-additional-terms', {
19 title: __( 'Additional Terms', 'woo-additional-terms' ),
20 description: __( 'Placeholder block for displaying additional terms checkbox.', 'woo-additional-terms' ),
21 icon: {
22 foreground: '#ffffff',
23 background: '#7f54b3',
24 src: el(
25 SVG,
26 { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24' },
27 el( Path, {
28 d: 'M4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4zm.8-4l.7.7 2-2V12h1V9.2l2 2 .7-.7-2-2H12v-1H9.2l2-2-.7-.7-2 2V4h-1v2.8l-2-2-.7.7 2 2H4v1h2.8l-2 2z',
29 } )
30 ),
31 },
32 category: 'woocommerce',
33 parent: [ 'woocommerce/checkout-fields-block' ],
34 attributes: {
35 lock: {
36 type: 'object',
37 default: {
38 remove: true,
39 move: false,
40 },
41 },
42 },
43 supports: {
44 align: false,
45 html: false,
46 multiple: false,
47 reusable: false,
48 },
49 edit: () => {
50 // eslint-disable-next-line react-hooks/rules-of-hooks
51 const blockProps = useBlockProps();
52 const { checkbox_label: checkboxLabel } = getSetting( '_woo_additional_terms_data', '' );
53
54 return !! checkboxLabel
55 ? el(
56 Disabled,
57 {},
58 el(
59 'div',
60 blockProps,
61 el(
62 'div',
63 {
64 className: 'woocommerce-terms-and-conditions-wrapper woo-additional-terms',
65 },
66 el(
67 CheckboxControl,
68 {
69 id: '_woo_additional_terms',
70 name: '_woo_additional_terms',
71 className: 'wc-block-checkout__terms',
72 },
73 el( 'span', {
74 style: { fontSize: 16 },
75 dangerouslySetInnerHTML: {
76 __html: checkboxLabel,
77 },
78 } )
79 )
80 )
81 ),
82 el(
83 InspectorControls,
84 {},
85 el(
86 Notice,
87 {
88 className: 'wc-blocks-sidebar-compatibility-notice is-dismissible',
89 isDismissible: false,
90 status: 'info',
91 },
92 el(
93 'p',
94 {},
95 __(
96 'Additional terms can be customized from the plugin’s settings page.',
97 'woo-additional-terms'
98 )
99 ),
100 el(
101 ExternalLink,
102 { href: 'https://mypreview.one/docs/woo-additional-terms' },
103 __( 'Visit our tutorial for full details.', 'woo-additional-terms' )
104 )
105 )
106 )
107 )
108 : el(
109 Notice,
110 {
111 isDismissible: false,
112 status: 'warning',
113 actions: [
114 {
115 className: 'wc-block-checkout__terms_notice-button',
116 label: __(
117 'Setup an additional Terms and Conditions page',
118 'woo-additional-terms'
119 ),
120 onClick: () => window.open( settingsUrl, '_blank' ),
121 },
122 ],
123 },
124 el(
125 'p',
126 {},
127 __( 'You haven’t set up an additional Terms and Conditions page.', 'woo-additional-terms' )
128 )
129 );
130 },
131 save: () => el( 'div', useBlockProps.save() ),
132 } );
133 } )( window.wp, window.wc );
134