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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / Features / Fulfillments / FulfillmentsSettings.php
woocommerce / src / Admin / Features / Fulfillments Last commit date
DataStore 1 month ago Providers 3 months ago Fulfillment.php 1 month ago FulfillmentException.php 3 months ago FulfillmentOrderNotes.php 3 months ago FulfillmentUtils.php 2 months ago FulfillmentsController.php 3 months ago FulfillmentsManager.php 2 months ago FulfillmentsRenderer.php 1 month ago FulfillmentsSettings.php 3 months ago FulfillmentsTracker.php 3 months ago OrderFulfillmentsRestController.php 1 month ago ShippingProviders.php 3 months ago
FulfillmentsSettings.php
205 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Automattic\WooCommerce\Admin\Features\Fulfillments;
6
7 use WC_Order;
8
9 /**
10 * FulfillmentsSettings class.
11 */
12 class FulfillmentsSettings {
13
14 /**
15 * Registers the hooks related to fulfillments settings.
16 */
17 public function register() {
18 add_filter( 'admin_init', array( $this, 'init_settings_auto_fulfill' ) );
19 add_action( 'woocommerce_order_status_processing', array( $this, 'auto_fulfill_items_on_processing' ), 10, 2 );
20 add_action( 'woocommerce_order_status_completed', array( $this, 'auto_fulfill_items_on_completed' ), 10, 2 );
21 }
22
23 /**
24 * Initialize settings for auto-fulfill options.
25 */
26 public function init_settings_auto_fulfill() {
27 add_filter( 'woocommerce_get_settings_products', array( $this, 'add_auto_fulfill_settings' ), 10, 2 );
28 }
29
30 /**
31 * Add auto-fulfill settings to the WooCommerce settings.
32 *
33 * @param array $settings The existing settings.
34 * @param string|null $current_section The current section being viewed.
35 *
36 * @return array Modified settings with auto-fulfill options added.
37 */
38 public function add_auto_fulfill_settings( array $settings, $current_section ): array {
39 if ( ! empty( $current_section ) ) {
40 return $settings;
41 }
42
43 $insertion_index = null;
44
45 // Find the index of the sectionend for 'Shop pages'.
46 foreach ( $settings as $index => $setting ) {
47 if (
48 isset( $setting['type'], $setting['id'] ) &&
49 'sectionend' === $setting['type'] &&
50 'catalog_options' === $setting['id'] // Woo core's ID for Shop pages section.
51 ) {
52 $insertion_index = $index + 1; // Insert after the sectionend.
53 break;
54 }
55 }
56
57 if ( is_null( $insertion_index ) ) {
58 return $settings; // fallback if not found.
59 }
60
61 $auto_fulfill_settings = array(
62 array(
63 'title' => 'Auto-fulfill items',
64 'desc' => '',
65 'type' => 'title',
66 'id' => 'auto_fulfill_options',
67 ),
68 array(
69 'title' => 'Virtual and downloadable items',
70 'desc' => 'Automatically mark downloadable items as fulfilled when the order is created.',
71 'id' => 'auto_fulfill_downloadable',
72 'type' => 'checkbox',
73 'checkboxgroup' => 'start',
74 'default' => 'yes',
75 ),
76 array(
77 'title' => 'Auto-fulfill items',
78 'desc' => 'Automatically mark virtual (non-downloadable) items as fulfilled when the order is created.',
79 'id' => 'auto_fulfill_virtual',
80 'type' => 'checkbox',
81 'checkboxgroup' => 'end',
82 'default' => 'no',
83 ),
84 array(
85 'type' => 'sectionend',
86 'id' => 'auto_fulfill_options',
87 ),
88 );
89
90 array_splice( $settings, $insertion_index, 0, $auto_fulfill_settings );
91
92 return $settings;
93 }
94
95 /**
96 * Automatically fulfill items in the order on the processing state.
97 *
98 * @param int $order_id The ID of the order being created.
99 * @param WC_Order $order The order object.
100 */
101 public function auto_fulfill_items_on_processing( int $order_id, $order ): void {
102 $order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
103
104 if ( ! $order || empty( $order->get_items() ) ) {
105 return;
106 }
107 $auto_fulfill_downloadable = 'yes' === get_option( 'auto_fulfill_downloadable', 'yes' );
108 $auto_fulfill_virtual = 'yes' === get_option( 'auto_fulfill_virtual', 'no' );
109
110 /**
111 * Filter to get the list of the item, or variant ID's that should be auto-fulfilled.
112 *
113 * @since 10.1.0
114 *
115 * @param array $auto_fulfill_items List of product or variant ID's to auto-fulfill.
116 * @param \WC_Order $order The order object.
117 *
118 * @return array Filtered list of product or variant ID's to auto-fulfill
119 */
120 $auto_fulfill_product_ids = apply_filters( 'woocommerce_fulfillments_auto_fulfill_products', array(), $order );
121 $auto_fulfill_items = array();
122
123 foreach ( $order->get_items() as $item ) {
124 /**
125 * Get the product associated with the item.
126 *
127 * @var \WC_Order_Item_Product $item
128 * @var \WC_Product $product
129 */
130 $product = $item->get_product();
131 if ( ! $product ) {
132 continue;
133 }
134
135 if ( ( $product->is_downloadable() && $auto_fulfill_downloadable )
136 || ( $product->is_virtual() && $auto_fulfill_virtual )
137 || in_array( $product->get_id(), $auto_fulfill_product_ids, true ) ) {
138 $auto_fulfill_items[] = $item;
139 }
140 }
141
142 if ( ! empty( $auto_fulfill_items ) ) {
143 $fulfillment = new Fulfillment();
144 $fulfillment->set_entity_type( WC_Order::class );
145 $fulfillment->set_entity_id( (string) $order_id );
146 $fulfillment->set_status( 'fulfilled' );
147 $fulfillment->set_items(
148 array_map(
149 function ( $item ) {
150 return array(
151 'item_id' => $item->get_id(),
152 'qty' => $item->get_quantity(),
153 );
154 },
155 $auto_fulfill_items
156 )
157 );
158 $fulfillment->save();
159 }
160
161 $order->update_meta_data( '_auto_fulfill_processed', true );
162 }
163
164 /**
165 * Automatically fulfill items in the order for orders that skip the processing state.
166 *
167 * @param int $order_id The ID of the order being created.
168 * @param WC_Order $order The order object.
169 */
170 public function auto_fulfill_items_on_completed( int $order_id, $order ): void {
171 $order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
172 if ( ! $order || empty( $order->get_items() ) ) {
173 return;
174 }
175
176 // If auto-fulfill already processed, skip.
177 if ( $order->get_meta( '_auto_fulfill_processed', true ) ) {
178 return;
179 }
180
181 // If fulfillments already exist, skip auto-fulfillment.
182 try {
183 /**
184 * Fulfillments data store.
185 *
186 * @var \Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore\FulfillmentsDataStore $fulfillment_data_store
187 */
188 $fulfillment_data_store = \WC_Data_Store::load( 'order-fulfillment' );
189 $fulfillments = $fulfillment_data_store->read_fulfillments( \WC_Order::class, (string) $order_id );
190 if ( ! empty( $fulfillments ) ) {
191 return;
192 }
193 } catch ( \Throwable $e ) {
194 wc_get_logger()->error(
195 sprintf( 'Failed to load fulfillments for order %d: %s', $order_id, $e->getMessage() ),
196 array( 'source' => 'fulfillments' )
197 );
198 return;
199 }
200
201 // Auto-fulfill items.
202 $this->auto_fulfill_items_on_processing( $order_id, $order );
203 }
204 }
205