'products', 'term' => (int) $term_id ), $args ) ); } protected static function product_ids_in( $term_id, $children = false ) { return get_posts( array( 'post_type' => 'product', 'post_status' => array( 'publish', 'draft', 'private', 'future', 'pending' ), 'posts_per_page' => -1, 'fields' => 'ids', 'orderby' => 'title', 'order' => 'ASC', 'hyperdrop_skip' => true, 'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => (int) $term_id, 'include_children' => $children, ), ), ) ); } public static function count( $term_id ) { return count( self::product_ids_in( $term_id, true ) ); } protected static function row( $p, $term_id, $mode, $via = '' ) { $id = $p->get_id(); $cats = array(); foreach ( wc_get_product_cat_ids( $id ) as $cid ) { if ( (int) $cid !== (int) $term_id ) { $t = get_term( $cid, 'product_cat' ); if ( $t && ! is_wp_error( $t ) ) { $cats[] = $t->name; } } } $stock = $p->managing_stock() ? sprintf( /* translators: %d: stock */ __( '%d in stock', 'hyperdrop' ), (int) $p->get_stock_quantity() ) : ( $p->is_in_stock() ? __( 'In stock', 'hyperdrop' ) : __( 'Out of stock', 'hyperdrop' ) ); ?> get_image( array( 44, 44 ) ) ); ?> get_name() ); ?> get_status() ) : ?>get_status() ) ); ?> get_sku() ) : ?>
get_sku() ); ?> get_price_html() ? $p->get_price_html() : '–' ); ?> ' . esc_html__( 'Collection not found.', 'hyperdrop' ) . '

'; return; } $direct = self::product_ids_in( $term_id ); $in_ids = self::product_ids_in( $term_id, true ); $all_ids = get_posts( array( 'post_type' => 'product', 'post_status' => array( 'publish', 'draft', 'private', 'future', 'pending' ), 'posts_per_page' => 1000, 'fields' => 'ids', 'orderby' => 'title', 'order' => 'ASC', 'hyperdrop_skip' => true, ) ); $out_ids = array_values( array_diff( $all_ids, $in_ids ) ); $view = get_term_link( $term ); ?>

←

name ) ); ?>

name; break; } } } self::row( $p, $term_id, 'in', $via ); } ?>

'dashboard' ) ) ); exit; } $n = 0; foreach ( array_filter( $ids ) as $pid ) { if ( 'product' !== get_post_type( $pid ) ) { continue; } if ( 'add' === $op ) { wp_set_object_terms( $pid, $term_id, 'product_cat', true ); } else { wp_remove_object_terms( $pid, $term_id, 'product_cat' ); // WooCommerce needs at least one category; fall back to the default one. if ( ! wc_get_product_cat_ids( $pid ) ) { $default = (int) get_option( 'default_product_cat', 0 ); if ( $default ) { wp_set_object_terms( $pid, $default, 'product_cat' ); } } } clean_post_cache( $pid ); ++$n; } if ( function_exists( 'wc_delete_product_transients' ) ) { wc_delete_product_transients(); } HyperDrop_Drop::flush_cache(); $msg = 'add' === $op /* translators: %d: count */ ? sprintf( _n( 'Added %d product to the drop.', 'Added %d products to the drop.', $n, 'hyperdrop' ), $n ) /* translators: %d: count */ : sprintf( _n( 'Removed %d product from the drop.', 'Removed %d products from the drop.', $n, 'hyperdrop' ), $n ); if ( ! $n ) { $msg = __( 'Nothing selected.', 'hyperdrop' ); } HyperDrop_Admin::flash( $msg ); wp_safe_redirect( self::url( $term_id ) ); exit; } }