'ids' ) ); if ( is_wp_error( $termIds ) || empty( $termIds ) ) { return array(); } $all = array(); foreach ( $termIds as $termId ) { $all[] = (int) $termId; foreach ( get_ancestors( (int) $termId, 'product_cat', 'taxonomy' ) as $ancestor ) { $all[] = (int) $ancestor; } } $rules = array(); foreach ( array_unique( $all ) as $termId ) { $rule = self::getCategoryRule( $termId ); if ( VisibilityRule::isRestricting( $rule ) ) { $rules[] = $rule; } } return $rules; } /** * Term ids of the categories that carry a restricting rule. * * @return int[] */ public static function getRestrictedCategoryIds(): array { $terms = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => false, 'fields' => 'ids', 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array( 'key' => self::TERM_MODE, 'value' => array( VisibilityRule::MODE_INCLUDE, VisibilityRule::MODE_EXCLUDE ), 'compare' => 'IN', ), ), 'tpt_visibility' => true, // our own get_terms filter leaves this query alone ) ); return is_wp_error( $terms ) ? array() : array_map( 'intval', $terms ); } /** * The roles a rule can name, for the admin checkbox lists: customer-facing roles plus guests. * * @return array role key => label */ public static function getRoleOptions(): array { return Roles::getOptions(); } public static function getModeOptions( bool $forProduct ): array { $options = array(); if ( $forProduct ) { $options[ VisibilityRule::MODE_INHERIT ] = __( 'Follow the category rules (default)', 'tier-pricing-table' ); } $options[ VisibilityRule::MODE_EVERYONE ] = __( 'Everyone', 'tier-pricing-table' ); $options[ VisibilityRule::MODE_INCLUDE ] = __( 'Only the selected roles', 'tier-pricing-table' ); $options[ VisibilityRule::MODE_EXCLUDE ] = __( 'Everyone except the selected roles', 'tier-pricing-table' ); return $options; } public static function getVersion(): string { return (string) get_option( self::VERSION_OPTION, '1' ); } public static function bumpVersion() { update_option( self::VERSION_OPTION, (string) time(), false ); } }