Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product custom meta data are not working for WooCommerce version 3.xx #237

Open
Shibly opened this issue Jan 3, 2018 · 0 comments
Open

Comments

@Shibly
Copy link

Shibly commented Jan 3, 2018

Product with custom field are not working in WoCommerce version 3.xxx . Current code:

        $wc_data = array(
            'title' => $data['name'],
            'sku' => trim($data['serial_number']),
            'status' => $status,
            'regular_price' => trim($data['selling_price']),
            'description' => stripslashes($data['description']),
            'managing_stock' => true,
            'stock_quantity' => trim($data['total_quantity']),
            'categories' => $cat_ids,
            'tags' => array($data['season_id']),
            'enable_html_description' => true
        );


        if (isset($data['product_image'])) {
            $wc_data['custom_meta']['custom_image_url'] = $data['product_image'];
        }

        if (isset($data['swatch_image'])) {
            $wc_data['custom_meta']['swatch_image_url'] = $data['swatch_image'];
        }

        if (isset($data['purchase_price'])) {
            $wc_data['custom_meta']['wholesale_price'] = $data['purchase_price'];
        }

        if (isset($data['color_name'])) {
            $wc_data['custom_meta']['product_color'] = $data['color_name'];
        }

        if (isset($data['material_name'])) {
            $wc_data['custom_meta']['product_materials'] = $data['material_name'];
        }

        if (isset($data['dimensions'])) {
            $wc_data['custom_meta']['product_dimensions'] = $data['dimensions'];
        }

        if (isset($data['construction'])) {
            $wc_data['custom_meta']['product_construction'] = $data['construction'];
        }

        if (isset($data['origin']) && $data['origin'] != '') {
            $wc_data['custom_meta']['product_origin'] = $data['origin'];
        }

        if (isset($data['note'])) {
            $wc_data['custom_meta']['product_season'] = $data['note'];
        }

        if (isset($data['product_gallery']) && count($data['product_gallery']) > 1) {
            $wc_data['custom_meta']['product_gallery'] = $data['product_gallery'];
        } else {
            $wc_data['custom_meta']['product_gallery'] = array();
        }

      $client = new WC_API_Client($store_url, $consumer_key, $consumer_secret, $options);
      $is_created = $client->products->create($wc_data);

Same code was working fine in WooCommerce version 2.xx

Thanks :)

@Shibly Shibly changed the title Product custom meta data are not showing for WooCommerce version 3.xx Product custom meta data are not working for WooCommerce version 3.xx Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant