Automattic\WooCommerce\Internal\ProductAttributesLookup

LookupDataStore::init_hooks()privateWC 1.0

Initialize the hooks used by the class.

{} Это метод класса: LookupDataStore{}

Хуков нет.

Возвращает

null. Ничего.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->init_hooks();

Код LookupDataStore::init_hooks() WC 6.9.1

private function init_hooks() {
	add_action(
		'woocommerce_run_product_attribute_lookup_update_callback',
		function ( $product_id, $action ) {
			$this->run_update_callback( $product_id, $action );
		},
		10,
		2
	);

	add_filter(
		'woocommerce_get_sections_products',
		function ( $products ) {
			if ( $this->check_lookup_table_exists() ) {
				$products['advanced'] = __( 'Advanced', 'woocommerce' );
			}
			return $products;
		},
		100,
		1
	);

	add_action(
		'woocommerce_rest_insert_product',
		function ( $product_post, $request ) {
			$this->on_product_created_or_updated_via_rest_api( $product_post, $request );
		},
		100,
		2
	);

	add_filter(
		'woocommerce_get_settings_products',
		function ( $settings, $section_id ) {
			if ( 'advanced' === $section_id && $this->check_lookup_table_exists() ) {
				$title_item = array(
					'title' => __( 'Product attributes lookup table', 'woocommerce' ),
					'type'  => 'title',
				);

				$regeneration_is_in_progress = $this->regeneration_is_in_progress();

				if ( $regeneration_is_in_progress ) {
					$title_item['desc'] = __( 'These settings are not available while the lookup table regeneration is in progress.', 'woocommerce' );
				}

				$settings[] = $title_item;

				if ( ! $regeneration_is_in_progress ) {
					$regeneration_aborted_warning =
						$this->regeneration_was_aborted() ?
						sprintf(
							"<p><strong style='color: #E00000'>%s</strong></p><p>%s</p>",
							__( 'WARNING: The product attributes lookup table regeneration process was aborted.', 'woocommerce' ),
							__( 'This means that the table is probably in an inconsistent state. It\'s recommended to run a new regeneration process or to resume the aborted process (Status - Tools - Regenerate the product attributes lookup table/Resume the product attributes lookup table regeneration) before enabling the table usage.', 'woocommerce' )
						) : null;

					$settings[] = array(
						'title'         => __( 'Enable table usage', 'woocommerce' ),
						'desc'          => __( 'Use the product attributes lookup table for catalog filtering.', 'woocommerce' ),
						'desc_tip'      => $regeneration_aborted_warning,
						'id'            => 'woocommerce_attribute_lookup_enabled',
						'default'       => 'no',
						'type'          => 'checkbox',
						'checkboxgroup' => 'start',
					);

					$settings[] = array(
						'title'         => __( 'Direct updates', 'woocommerce' ),
						'desc'          => __( 'Update the table directly upon product changes, instead of scheduling a deferred update.', 'woocommerce' ),
						'id'            => 'woocommerce_attribute_lookup_direct_updates',
						'default'       => 'no',
						'type'          => 'checkbox',
						'checkboxgroup' => 'start',
					);
				}

				$settings[] = array( 'type' => 'sectionend' );
			}
			return $settings;
		},
		100,
		2
	);
}