WC_Webhook::get_default_topic_hooks │ public static │ WC 10.9.0

Get the default topic-hooks map (topic => array of hook names).

Source of truth for which default-resource/default-event webhook topics can deliver. Used by wc_is_webhook_valid_topic() derive the default-pair allowlist so the validator and the map cannot drift.

The woocommerce_webhook_topic_hooks is applied here. When called statically (without a webhook context, e.g. from the topic validator), a fresh, unsaved WC_Webhook instance is passed as the filter's second argument so callbacks registered with accepted_args = 2 keep working. Those callbacks should not rely on the second argument exposing per-webhook state in that call path (get_id() returns 0, get_topic() is empty).

Method of the class: WC_Webhook{}

Hooks from the method

Returns

array.

Usage

$result = WC_Webhook::get_default_topic_hooks( $webhook );
$webhook(WC_Webhook|null)
Optional webhook instance to pass as the filter's context argument. A fresh unsaved instance is created when omitted.
Default: null

Changelog

Since 10.9.0 Introduced.

WC_Webhook::get_default_topic_hooks() code WC 11.1.2

public static function get_default_topic_hooks( $webhook = null ) {
	if ( ! $webhook instanceof WC_Webhook ) {
		$webhook = new self();
	}

	$topic_hooks = array(
		'coupon.created'    => array(
			'woocommerce_process_shop_coupon_meta',
			'woocommerce_new_coupon',
		),
		'coupon.updated'    => array(
			'woocommerce_process_shop_coupon_meta',
			'woocommerce_update_coupon',
		),
		'coupon.deleted'    => array(
			'wp_trash_post',
		),
		'coupon.restored'   => array(
			'untrashed_post',
		),
		'customer.created'  => array(
			'user_register',
			'woocommerce_created_customer',
			'woocommerce_new_customer',
		),
		'customer.updated'  => array(
			'profile_update',
			'woocommerce_update_customer',
		),
		'customer.deleted'  => array(
			'delete_user',
		),
		'order.created'     => array(
			'woocommerce_new_order',
		),
		'order.updated'     => array(
			'woocommerce_update_order',
			'woocommerce_order_refunded',
		),
		'order.deleted'     => array(
			'wp_trash_post',
			'woocommerce_trash_order',
		),
		'order.restored'    => array(
			'untrashed_post',
			'woocommerce_untrash_order',
		),
		'product.created'   => array(
			'woocommerce_process_product_meta',
			'woocommerce_new_product',
			'woocommerce_new_product_variation',
		),
		'product.updated'   => array(
			'woocommerce_process_product_meta',
			'woocommerce_update_product',
			'woocommerce_update_product_variation',
		),
		'product.deleted'   => array(
			'wp_trash_post',
		),
		'product.restored'  => array(
			'untrashed_post',
		),
		'product.published' => array(
			'woocommerce_product_published',
		),
	);

	/**
	 * Filters the map of webhook topics to their registered hook names.
	 *
	 * @since 2.2.0
	 * @param array      $topic_hooks Map of topic name to array of hook names.
	 * @param WC_Webhook $webhook     The webhook instance. May be a fresh,
	 *                                unsaved instance when called from
	 *                                `WC_Webhook::get_default_topic_hooks()`
	 *                                without a webhook context.
	 */
	return apply_filters( 'woocommerce_webhook_topic_hooks', $topic_hooks, $webhook );
}