Automattic\WooCommerce\Internal\Fulfillments
FulfillmentsSettings::add_auto_fulfill_settings
Add auto-fulfill settings to the WooCommerce settings.
Method of the class: FulfillmentsSettings{}
No Hooks.
Returns
Array. Modified settings with auto-fulfill options added.
Usage
$FulfillmentsSettings = new FulfillmentsSettings(); $FulfillmentsSettings->add_auto_fulfill_settings( $settings, $current_section ): array;
- $settings(array) (required)
- The existing settings.
- $current_section(string|null) (required)
- The current section being viewed.
FulfillmentsSettings::add_auto_fulfill_settings() FulfillmentsSettings::add auto fulfill settings code WC 10.3.3
public function add_auto_fulfill_settings( array $settings, $current_section ): array {
if ( ! empty( $current_section ) ) {
return $settings;
}
$insertion_index = null;
// Find the index of the sectionend for 'Shop pages'.
foreach ( $settings as $index => $setting ) {
if (
isset( $setting['type'], $setting['id'] ) &&
'sectionend' === $setting['type'] &&
'catalog_options' === $setting['id'] // Woo core's ID for Shop pages section.
) {
$insertion_index = $index + 1; // Insert after the sectionend.
break;
}
}
if ( is_null( $insertion_index ) ) {
return $settings; // fallback if not found.
}
$auto_fulfill_settings = array(
array(
'title' => 'Auto-fulfill items',
'desc' => '',
'type' => 'title',
'id' => 'auto_fulfill_options',
),
array(
'title' => 'Virtual and downloadable items',
'desc' => 'Automatically mark downloadable items as fulfilled when the order is created.',
'id' => 'auto_fulfill_downloadable',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'default' => 'yes',
),
array(
'title' => 'Auto-fulfill items',
'desc' => 'Automatically mark virtual (non-downloadable) items as fulfilled when the order is created.',
'id' => 'auto_fulfill_virtual',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'default' => 'no',
),
array(
'type' => 'sectionend',
'id' => 'auto_fulfill_options',
),
);
array_splice( $settings, $insertion_index, 0, $auto_fulfill_settings );
return $settings;
}