Skip to content

Commit d78130f

Browse files
committed
WIP
1 parent ca02621 commit d78130f

File tree

2 files changed

+28
-123
lines changed

2 files changed

+28
-123
lines changed

wordpress/coopcycle-extend-woo-core.php

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class Coopcycle_Extend_Woo_Core
88
{
9-
109
/**
1110
* Plugin Identifier, unique to each plugin.
1211
*
@@ -21,8 +20,8 @@ public function init()
2120
{
2221
$this->save_shipping_date();
2322
$this->show_shipping_date_in_order();
24-
// $this->show_shipping_instructions_in_order_confirmation();
25-
// $this->show_shipping_instructions_in_order_email();
23+
$this->show_shipping_date_in_order_confirmation();
24+
$this->show_shipping_date_in_order_email();
2625
}
2726

2827
/**
@@ -75,71 +74,51 @@ function (\WC_Order $order) {
7574
/**
7675
* Adds the pickup date and time on the order confirmation page.
7776
*/
78-
private function show_shipping_instructions_in_order_confirmation()
77+
private function show_shipping_date_in_order_confirmation()
7978
{
8079
add_action(
81-
'woocommerce_thankyou',
82-
function (int $order_id) {
83-
$order = wc_get_order($order_id);
84-
$shipping_methods = $order->get_shipping_methods();
85-
$shipping_method = reset( $shipping_methods );
80+
'woocommerce_order_details_after_customer_address',
81+
function ($type, $order) {
82+
if ($type === 'shipping') {
83+
if ($order->meta_exists('shipping_date')) {
8684

87-
if ($shipping_method?->get_method_id() === 'pickup_location') {
88-
$pickup_date = $order->get_meta('your-extension-name_pickup_date');
85+
$shipping_date = $order->get_meta('shipping_date');
8986

90-
if ('' !== $pickup_date) {
9187
printf(
92-
"<h2>%s</h2>
93-
<p>%s %s</p>
94-
<p><strong>%s</strong><br>%s</p>
95-
<p><strong>%s</strong><br>%s</p>",
96-
esc_html__('Order pickup', $this->name),
97-
esc_html__('You chose', $this->name),
98-
$order->get_shipping_method(),
99-
esc_html__('Pickup location', $this->name),
100-
$shipping_method->get_meta('pickup_address'),
101-
esc_html__('Pickup date and time', $this->name),
102-
esc_html(wp_date('j F Y at H:i', strtotime($pickup_date))),
88+
"<strong>%s</strong>
89+
<span>%s</span>",
90+
esc_html__('Shipping date', $this->name),
91+
esc_html($shipping_date)
10392
);
10493
}
10594
}
10695
},
107-
priority: 9, accepted_args: 1
96+
priority: 9,
97+
accepted_args: 2
10898
);
10999
}
110100

111101
/**
112-
* Adds the pickup date and time on the order confirmation email.
102+
* Adds the shipping date and time on the order confirmation email.
113103
*/
114-
private function show_shipping_instructions_in_order_email()
104+
private function show_shipping_date_in_order_email()
115105
{
116106
add_action(
117107
'woocommerce_email_after_order_table',
118108
function ($order, $sent_to_admin, $plain_text, $email) {
119-
$shipping_methods = $order->get_shipping_methods();
120-
$shipping_method = reset( $shipping_methods );
121-
122-
if ($shipping_method?->get_method_id() === 'pickup_location') {
123-
$pickup_date = $order->get_meta('your-extension-name_pickup_date');
109+
if ($order->meta_exists('shipping_date')) {
110+
$shipping_date = $order->get_meta('shipping_date');
124111

125-
if ('' !== $pickup_date) {
126-
printf(
127-
"<h2>%s</h2>
128-
<p>%s %s</p>
129-
<p><strong>%s</strong><br>%s</p>
130-
<p><strong>%s</strong><br>%s</p>",
131-
esc_html__('Order pickup', $this->name),
132-
esc_html__('You chose', $this->name),
133-
$order->get_shipping_method(),
134-
esc_html__('Pickup location', $this->name),
135-
$shipping_method->get_meta('pickup_address'),
136-
esc_html__('Pickup date and time', $this->name),
137-
esc_html(wp_date('j F Y at H:i', strtotime($pickup_date))),
138-
);
139-
}
112+
printf(
113+
"<h2>%s</h2>
114+
<p>%s</p>",
115+
esc_html__('Shipping date', $this->name),
116+
esc_html($shipping_date)
117+
);
140118
}
141119
},
142-
priority: 10, accepted_args: 4
120+
priority: 10,
121+
accepted_args: 4
143122
);
144123
}
145124
}

wordpress/src/shipping-date-picker/index.js

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,18 @@
22
* External dependencies
33
*/
44
import { registerPlugin } from '@wordpress/plugins';
5-
import { ExperimentalOrderShippingPackages, extensionCartUpdate } from '@woocommerce/blocks-checkout';
6-
import { getSetting } from '@woocommerce/settings';
7-
import { SelectControl } from '@wordpress/components'
8-
import apiFetch from '@wordpress/api-fetch';
9-
import { useState, useEffect } from '@wordpress/element'
10-
import { cartStore } from '@woocommerce/block-data';
11-
import { useSelect } from '@wordpress/data';
125

136
/**
147
* Internal dependencies
158
*/
169
import './style.scss';
1710

18-
// import { registerFilters } from './filters';
19-
// import { ExampleComponent } from './ExampleComponent';
20-
21-
const MyCustomComponent = ({ cart }) => {
22-
23-
const [ selected, setSelected ] = useState(false);
24-
const [ options, setOptions ] = useState([]);
25-
26-
// https://developer.woocommerce.com/docs/cart-and-checkout-frequently-asked-questions/#how-do-i-react-to-changes-to-the-cart-or-checkout-e-g-shipping-method-selection-or-address-changes
27-
// https://github.com/woocommerce/woocommerce/tree/1ae5681bc5d56775a9d89c4d744531318af773ed/plugins/woocommerce/client/blocks/docs/third-party-developers/extensibility/data-store
28-
// https://github.com/woocommerce/woocommerce/blob/1ae5681bc5d56775a9d89c4d744531318af773ed/plugins/woocommerce/client/blocks/docs/third-party-developers/extensibility/data-store/cart.md
29-
30-
const { shippingRates } = useSelect(
31-
(select) => select(cartStore).getCartData(),
32-
[]
33-
);
34-
35-
useEffect( () => {
36-
37-
const isSelected = shippingRates.reduce((accumulator, currentValue) => {
38-
if (accumulator === true) {
39-
return true
40-
}
41-
42-
return currentValue.shipping_rates.reduce((acc, currVal) => {
43-
if (acc === true) {
44-
return true;
45-
}
46-
47-
return currVal.method_id === 'coopcycle_shipping_method' && currVal.selected;
48-
}, false)
49-
50-
}, false);
51-
52-
if (isSelected) {
53-
apiFetch( { path: '/coopcycle/v1/shipping-date-options' } ).then((data) => {
54-
setOptions(data.options)
55-
});
56-
}
57-
58-
setSelected(isSelected)
59-
60-
}, [ shippingRates ] );
61-
62-
if (!selected) {
63-
return null;
64-
}
65-
66-
return <SelectControl
67-
options={ options }
68-
onChange={ (value) => {
69-
console.log(value)
70-
extensionCartUpdate({
71-
namespace: 'coopcycle/shipping-date-picker',
72-
data: { value }
73-
});
74-
}}
75-
/>;
76-
};
77-
78-
// const exampleDataFromSettings = getSetting( '{{slug}}_data' );
79-
8011
// https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#experimentalordershippingpackages
8112
// https://developer.woocommerce.com/docs/cart-and-checkout-slot-and-fill/
8213

8314
const render = () => {};
8415

85-
registerPlugin( 'shipping-date-picker', {
16+
registerPlugin('shipping-date-picker', {
8617
render,
8718
scope: 'woocommerce-checkout',
88-
} );
89-
90-
91-
// console.log('PLOP');
92-
93-
// registerFilters();
19+
});

0 commit comments

Comments
 (0)