Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::set_custom_taxonomies()publicWC 1.0

Set custom taxonomies for the order.

Note: This is re-implementation of part of WP core's wp_insert_post Since the code block that set custom taxonomies is not filterable, we have to re-implement it.

Метод класса: OrdersTableDataStore{}

Хуков нет.

Возвращает

null. Ничего (null).

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

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->set_custom_taxonomies( $order, $sanitized_tax_input );
$order(\WC_Abstract_Order) (обязательный)
Order object.
$sanitized_tax_input(массив) (обязательный)
Sanitized taxonomy input.

Код OrdersTableDataStore::set_custom_taxonomies() WC 9.4.2

public function set_custom_taxonomies( \WC_Abstract_Order $order, array $sanitized_tax_input ) {
	if ( empty( $sanitized_tax_input ) ) {
		return;
	}

	foreach ( $sanitized_tax_input as $taxonomy => $tags ) {
		$taxonomy_obj = get_taxonomy( $taxonomy );

		if ( ! $taxonomy_obj ) {
			/* translators: %s: Taxonomy name. */
			_doing_it_wrong( __FUNCTION__, esc_html( sprintf( __( 'Invalid taxonomy: %s.', 'woocommerce' ), $taxonomy ) ), '7.9.0' );
			continue;
		}

		// array = hierarchical, string = non-hierarchical.
		if ( is_array( $tags ) ) {
			$tags = array_filter( $tags );
		}

		if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
			wp_set_post_terms( $order->get_id(), $tags, $taxonomy );
		}
	}
}