-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout-blocks-initialize.php
57 lines (51 loc) · 1.54 KB
/
checkout-blocks-initialize.php
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
<?php
use Automattic\WooCommerce\StoreApi\StoreApi;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema;
add_action(
'woocommerce_blocks_loaded',
function() {
require_once 'class-blocks-integration.php';
add_action(
'woocommerce_blocks_checkout_block_registration',
function( $integration_registry ) {
$integration_registry->register( new Blocks_Integration() );
}
);
if ( function_exists( 'woocommerce_store_api_register_endpoint_data' ) ) {
woocommerce_store_api_register_endpoint_data(
array(
'endpoint' => CheckoutSchema::IDENTIFIER,
'namespace' => 'checkout-block-example',
'data_callback' => 'cb_data_callback',
'schema_callback' => 'cb_schema_callback',
'schema_type' => ARRAY_A,
)
);
}
}
);
/**
* Callback function to register endpoint data for blocks.
*
* @return array
*/
function cb_data_callback() {
return array(
'gift_message' => '',
);
}
/**
* Callback function to register schema for data.
*
* @return array
*/
function cb_schema_callback() {
return array(
'gift_message' => array(
'description' => __( 'Gift Message', 'checkout-block-example' ),
'type' => array( 'string', 'null' ),
'readonly' => true,
),
);
}