1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17
18 class WC_Meta_Box_Product_Images {
19
20 21 22
23 public static function output( $post ) {
24 ?>
25 <div id="product_images_container">
26 <ul class="product_images">
27 <?php
28 if ( metadata_exists( 'post', $post->ID, '_product_image_gallery' ) ) {
29 $product_image_gallery = get_post_meta( $post->ID, '_product_image_gallery', true );
30 } else {
31
32 $attachment_ids = get_posts( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_key=_woocommerce_exclude_image&meta_value=0' );
33 $attachment_ids = array_diff( $attachment_ids, array( get_post_thumbnail_id() ) );
34 $product_image_gallery = implode( ',', $attachment_ids );
35 }
36
37 $attachments = array_filter( explode( ',', $product_image_gallery ) );
38
39 if ( $attachments )
40 foreach ( $attachments as $attachment_id ) {
41 echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
42 ' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '
43 <ul class="actions">
44 <li><a href="#" class="delete tips" data-tip="' . __( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a></li>
45 </ul>
46 </li>';
47 }
48 ?>
49 </ul>
50
51 <input type="hidden" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( $product_image_gallery ); ?>" />
52
53 </div>
54 <p class="add_product_images hide-if-no-js">
55 <a href="#" data-choose="<?php _e( 'Add Images to Product Gallery', 'woocommerce' ); ?>" data-update="<?php _e( 'Add to gallery', 'woocommerce' ); ?>" data-delete="<?php _e( 'Delete image', 'woocommerce' ); ?>" data-text="<?php _e( 'Delete', 'woocommerce' ); ?>"><?php _e( 'Add product gallery images', 'woocommerce' ); ?></a>
56 </p>
57 <?php
58 }
59
60 61 62
63 public static function save( $post_id, $post ) {
64 $attachment_ids = array_filter( explode( ',', wc_clean( $_POST['product_image_gallery'] ) ) );
65
66 update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
67 }
68 }