Reputation: 67
I've just searched for a quick solution.
I need a multiple "Product picker" in my Woocommerce products, as custom field. I found this Tutorial: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ but it doesn't work.
Its just blank:
Have you any idea?
Upvotes: 2
Views: 720
Reputation: 26
that code is only works with WooCommerce 2.3 or lower
If you wanna use it in a WooCommerce 3 or more, you will have to use something like this:
?>
<p class="form-field">
<label for="related_ids"><?php _e( 'Name of te field', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="related_ids" name="related_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-exclude="<?php echo intval( $post->ID ); ?>">
<?php
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Tooltip text', 'woocommerce' ) ); ?>
</p>
<?php
Cheers!
Upvotes: 1