The array of conditionals. */ public static function get_conditionals() { return [ WooCommerce_Version_Conditional::class, Woo_SEO_Inactive_Conditional::class, ]; } /** * Constructs Support_Integration. * * @param Dynamic_Product_Permalinks_Conditional $dynamic_product_permalinks_conditional The Dynamic_Product_Permalinks_Conditional. */ public function __construct( Dynamic_Product_Permalinks_Conditional $dynamic_product_permalinks_conditional ) { $this->dynamic_product_permalinks_conditional = $dynamic_product_permalinks_conditional; } /** * Registers the hooks for this integration. * * @return void */ public function register_hooks() { \add_filter( 'wc_product_post_type_link_product_cat', [ $this, 'restore_legacy_permalink_category' ], 10, 2 ); } /** * Handles the product category link filter. Basically restores the pre-10.5 behavior for now. * * @param WP_Term $category The deepest category (new default behavior). * @param WP_Term[] $terms All categories assigned to the product. * * @return WP_Term The category to use in the permalink. */ public function restore_legacy_permalink_category( $category, $terms ) { if ( $this->dynamic_product_permalinks_conditional->is_met() ) { return $category; } $sorted_terms = \wp_list_sort( $terms, [ 'parent' => 'DESC', 'term_id' => 'ASC', ], ); return $sorted_terms[0]; } }