Jake Vanderwerf
2026-08-25 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a
inc/meta/Meta.php
@@ -132,14 +132,134 @@
         $meta = [];
      }
      $meta = array_map(fn($value) => maybe_unserialize($value[0]), $meta);
      $this->fields = [];
      if (class_exists('WooCommerce') && $this->type === 'post' && $this->wpObject->post_type??'' === 'product') {
         $fields['post_title'] = [
            'type'   => 'text',
            'label'  => 'Title',
         ];
         $fields['post_content'] = [
            'type'   => 'text',
            'label'  => 'Content',
         ];
         $fields['post_excerpt'] = [
            'type'   => 'text',
            'label'  => 'Short Description',
         ];
         $fields['post_id'] = [
            'type'   => 'text',
            'label'  => 'ID',
         ];
         $fields['_stock'] = [
            'type' => 'number',
            'label' => 'Stock',
            'default'   => null
         ];
         $fields['_stock_status'] = [
            'type'   => 'select',
            'label'  => 'Stock Status',
            'default'   => 'instock',
            'options'   => [
               'instock'   => 'In Stock',
               'outofstock'   => 'Out of Stock',
               'onbackorder'     => 'On Backorder'
            ]
         ];
         $fields['_price'] = [
            'type'      => 'text',
            'subtype'   => 'number',
            'label'     => 'Price'
         ];
         $product = wc_get_product($id);
         $fields['sku'] = [
            'type'   => 'text',
            'label'  => 'SKU',
         ];
         $out = [];
         if ($product && $product->is_type('variable')) {
            $var = $product->get_children();
            $var = array_filter(array_map(function($v) {
               return wc_get_product($v);
            }, $var));
            $title= $product->get_title();
            foreach ($var as $variation) {
               $out[] = [
                  'id'  => $variation->get_id(),
                  'sku' => $variation->get_sku(),
                  'title'  => str_replace($title.' - ', '', $variation->get_name()),
                  'price'  => $variation->get_price(),
                  'description'=> $variation->get_short_description(),
                  'sale'   => $variation->get_sale_price(),
                  'img' => $variation->get_image_id(),
                  'stock'  => $variation->get_stock_quantity(),
                  'stock_status' => $variation->get_stock_status()
               ];
            }
         }
         if (!empty($out)) {
            $this->fields['variations'] = new Field('variations', $out, [
               'type'   => 'repeater',
               'label'  => 'Variations',
               'fields' => [
                  'id'  => [
                     'type'   => 'text',
                     'subtype'   => 'number',
                     'label'  => 'Variation ID',
                  ],
                  'sku' => [
                     'type'   => 'text',
                     'label'  => 'Stock Keeping Unit (SKU)'
                  ],
                  'title'  => [
                     'type'   => 'text',
                     'label'  => 'Variation Title'
                  ],
                  'price'  => [
                     'type'   => 'text',
                     'subtype'   => 'number',
                     'label'  => 'Variation Price'
                  ],
                  'sale'   => [
                     'type'   => 'text',
                     'subtype'   => 'number',
                     'label'  => 'Sale Price',
                  ],
                  'image'  => [
                     'type'   => 'text',
                     'subtype'   => 'number',
                     'label'  => 'Variation Image ID'
                  ],
                  'stock'  => [
                     'type'   => 'text',
                     'label'  => 'Stock Quantity'
                  ],
                  'stock_status' => [
                     'type'   => 'text',
                     'label'  => 'Stock Status'
                  ]
               ]
            ]);
         }
      }
      foreach ($fields as $fieldName => $config) {
         $fieldName = jvbNoBase($fieldName);
         $value = '';
         if ($this->type === 'option') {
            $value = get_option(BASE . $fieldName, $config['default'] ?? '');
         } else if (
            $this->wpObject && property_exists($this->wpObject, $fieldName)
            || $type === 'user' && $this->wpObject && property_exists($this->wpObject->data, $fieldName)) {
            ($this->wpObject && property_exists($this->wpObject, $fieldName))
            || ($type === 'user' && $this->wpObject && property_exists($this->wpObject->data, $fieldName))) {
            $config['wp'] = true;
            $value = $this->wpObject->$fieldName;