Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::set_custom_taxonomies
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.
Method of the class: OrdersTableDataStore{}
No Hooks.
Returns
null. Nothing (null).
Usage
$OrdersTableDataStore = new OrdersTableDataStore(); $OrdersTableDataStore->set_custom_taxonomies( $order, $sanitized_tax_input );
- $order(WC_Abstract_Order) (required)
- Order object.
- $sanitized_tax_input(array) (required)
- Sanitized taxonomy input.
OrdersTableDataStore::set_custom_taxonomies() OrdersTableDataStore::set custom taxonomies code WC 10.7.0
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 );
}
}
}