Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'rwmb_meta_boxes', 'add_image_boxes' );
- function add_image_boxes($meta_boxes){
- $post_id = false;
- if (isset($_GET['post'])){
- $post_id = intval($_GET['post']);
- } else{
- // return; ------- here
- }
- if ($post_id){
- $product = wc_get_product($post_id);
- }
- // if (is_a($product, "WC_Product")){ ------- here
- $args = array(
- 'taxonomy' => 'pa_color',
- 'object_ids' => $post_id,
- );
- $colors = get_terms($args);
- $fields = array();
- foreach($colors as $color){
- $fields[] = [
- 'type' => 'image_advanced',
- 'max_status' => false,
- 'name' => "Add images of " . $color->name,
- 'id' => "method1" . $color->slug,
- ];
- }
- $meta_boxes[] = [
- 'title' => 'Add images of the different colors',
- 'id' => 'add_images_of_the_different_colors',
- 'post_types' => ['product'],
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => $fields,
- ];
- // } ------- here
- foreach($colors as $color){
- $meta_boxes[] = [
- 'title' => "Add images of " . $color->name,
- 'id' => 'method2' . $color->slug,
- 'post_types' => ['product'],
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => [
- [
- 'type' => 'image_advanced',
- 'id' => 'method2' . $color->slug,
- 'name' => 'Add images',
- 'max_status' => false,
- ],
- ],
- ];
- }
- return $meta_boxes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement