PluginProbe
Packeta / 2.3.2
Packeta v2.3.2
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / PacketaWidget / index.js

index.js in Packeta 2.3.2, at src/PacketaWidget/index.js

53 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Block registration.
3 *
4 * @package Packetery
5 */
6
7 import { registerBlockType } from '@wordpress/blocks';
8 import { registerCheckoutBlock } from '@woocommerce/blocks-checkout';
9
10 import metadata from './block.json';
11 import { Edit } from './Edit';
12 import { View } from './View';
13 import { __ } from '@wordpress/i18n';
14 import { saveShippingAndPaymentMethods } from './saveShippingAndPaymentMethods';
15
16 registerBlockType( metadata, {
17 title: __( 'title', 'packeta' ),
18 description: __( 'description', 'packeta' ),
19 edit: Edit,
20 } );
21
22 registerCheckoutBlock( {
23 metadata,
24 component: View,
25 } );
26
27 const { extensionCartUpdate } = wc.blocksCheckout;
28
29 wp.hooks.addAction( 'experimental__woocommerce_blocks-checkout-set-selected-shipping-rate', 'packetery-js-hooks', function ( shipping ) {
30 saveShippingAndPaymentMethods( shipping, null );
31 } );
32
33 wp.hooks.addAction( 'experimental__woocommerce_blocks-checkout-set-active-payment-method', 'packetery-js-hooks', function ( payment ) {
34 saveShippingAndPaymentMethods( null, payment );
35 } );
36
37 // Used to clear values upon checkout page reload. It is needed to save something.
38 wp.hooks.addAction( 'experimental__woocommerce_blocks-checkout-render-checkout-form', 'packetery-js-hooks', function ( form ) {
39 extensionCartUpdate( {
40 namespace: 'packetery-js-hooks',
41 data: {
42 shipping_method: 'n/a',
43 payment_method: 'n/a',
44 },
45 } );
46 } );
47
48 wp.hooks.addAction( 'packetery_save_shipping_and_payment_methods', 'packetery-js-hooks', function ( shippingRateId, paymentId ) {
49 const shippingObject = shippingRateId ? { shippingRateId: shippingRateId } : null;
50 const paymentObject = paymentId !== '' ? { value: paymentId } : null;
51 saveShippingAndPaymentMethods( shippingObject, paymentObject );
52 } );
53