PluginProbe
Additional Terms Lite for WooCommerce / 1.5.0
Additional Terms Lite for WooCommerce v1.5.0
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.5.0, at assets/js/block.js

108 lines 2.5 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 { useBlockProps } = wp.blockEditor;
11 const { Disabled, 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
17 registerBlockType( 'mypreview/woo-additional-terms', {
18 title: __( 'Additional Terms', 'woo-additional-terms' ),
19 description: __( 'Placeholder block for displaying additional terms checkbox.', 'woo-additional-terms' ),
20 icon: {
21 foreground: '#ffffff',
22 background: '#7f54b3',
23 src: el(
24 SVG,
25 { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24' },
26 el( Path, {
27 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',
28 } )
29 ),
30 },
31 category: 'woocommerce',
32 parent: [ 'woocommerce/checkout-fields-block' ],
33 attributes: {
34 lock: {
35 type: 'object',
36 default: {
37 remove: true,
38 move: false,
39 },
40 },
41 checkbox: {
42 type: 'boolean',
43 default: false,
44 },
45 },
46 supports: {
47 align: false,
48 html: false,
49 multiple: false,
50 reusable: false,
51 },
52 edit: () => {
53 // eslint-disable-next-line react-hooks/rules-of-hooks
54 const blockProps = useBlockProps();
55 const { notice } = getSetting( '_woo_additional_terms_data', '' );
56
57 return notice
58 ? el(
59 Disabled,
60 {},
61 el(
62 'div',
63 blockProps,
64 el(
65 CheckboxControl,
66 {
67 id: '_woo_additional_terms',
68 checked: false,
69 },
70 el( 'span', {
71 dangerouslySetInnerHTML: {
72 __html: notice,
73 },
74 } )
75 )
76 )
77 )
78 : el(
79 Notice,
80 {
81 isDismissible: false,
82 status: 'warning',
83 actions: [
84 {
85 className: 'wc-block-checkout__terms_notice-button',
86 label: __(
87 'Setup an additional Terms and Conditions page',
88 'woo-additional-terms'
89 ),
90 onClick: () =>
91 window.open(
92 `${ ADMIN_URL }admin.php?page=wc-settings&tab=woo-additional-terms`,
93 '_blank'
94 ),
95 },
96 ],
97 },
98 el(
99 'p',
100 {},
101 __( 'You don’t have additional Terms and Conditions page set up.', 'woo-additional-terms' )
102 )
103 );
104 },
105 save: () => el( 'div', useBlockProps.save() ),
106 } );
107 } )( window.wp, window.wc );
108