Skip to content

Trying to create product in WC REST API v2 #23

@chamster

Description

@chamster

The following code creates a new product, but doesn't create the meta. Would this be expected to work? If so, can you see anything in the code that doesn't look right? Thanks.

WC REST API v2
WC v 3.0.9

<?php 

// Setup:
require('../../../../vendor/autoload.php');

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'https://mysite.com', // Your store URL
    'ck_xxxxxxxxxxxx', // Your consumer key
    'cs_xxxxxxxxxxxxx, // Your consumer secret
    [
        'wp_api' => true, // Enable the WP REST API integration
        'version' => 'wc/v2' // WooCommerce WP REST API version
    ]
);
	
$data = [
    'name' => 'My New product Name',
	'custom_meta' => [
            'gb_item_id' => '24680'
        ]
];

print_r($woocommerce->post('products', $data));

?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions