WC_Brands_Admin::add_coupon_brands_fields()publicWC 9.4.0

Display coupon filter fields relating to brands.

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

Хуков нет.

Возвращает

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

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

$WC_Brands_Admin = new WC_Brands_Admin();
$WC_Brands_Admin->add_coupon_brands_fields();

Список изменений

С версии 9.4.0 Введена.

Код WC_Brands_Admin::add_coupon_brands_fields() WC 9.4.2

<?php
public function add_coupon_brands_fields() {
	global $post;
	// Brands.
	?>
	<p class="form-field"><label for="product_brands"><?php esc_html_e( 'Product brands', 'woocommerce' ); ?></label>
		<select id="product_brands" name="product_brands[]" style="width: 50%;"  class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'Any brand', 'woocommerce' ); ?>">
			<?php
			$category_ids = (array) get_post_meta( $post->ID, 'product_brands', true );
			$categories   = get_terms(
				array(
					'taxonomy'   => 'product_brand',
					'orderby'    => 'name',
					'hide_empty' => false,
				)
			);

			if ( $categories ) {
				foreach ( $categories as $cat ) {
					echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids, true ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
				}
			}
			?>
		</select>
		<?php
			echo wc_help_tip( esc_html__( 'A product must be associated with this brand for the coupon to remain valid or, for "Product Discounts", products with these brands will be discounted.', 'woocommerce' ) );
			// Exclude Brands.
		?>
	<p class="form-field"><label for="exclude_product_brands"><?php esc_html_e( 'Exclude brands', 'woocommerce' ); ?></label>
		<select id="exclude_product_brands" name="exclude_product_brands[]" style="width: 50%;"  class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'No brands', 'woocommerce' ); ?>">
			<?php
			$category_ids = (array) get_post_meta( $post->ID, 'exclude_product_brands', true );
			$categories   = get_terms(
				array(
					'taxonomy'   => 'product_brand',
					'orderby'    => 'name',
					'hide_empty' => false,
				)
			);

			if ( $categories ) {
				foreach ( $categories as $cat ) {
					echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids, true ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
				}
			}
			?>
		</select>
		<?php
			echo wc_help_tip( esc_html__( 'Product must not be associated with these brands for the coupon to remain valid or, for "Product Discounts", products associated with these brands will not be discounted.', 'woocommerce' ) );
}