Skip to content

Creating a Product Category #21

Description

@stevenhardy-digital

Hello,

I am trying to create a product with a product category and thumbnail (not worked on this yet).

I am hoping you can help. How would you recommend doing this please?

$product = Product::create([
                'post_title' => 'Product name',
                'post_content' => 'Post description',
                'post_status' => 'publish',
                'post_type' => 'product'
                ]
        );
        $product->createMeta([
            '_sku' => $row['skucode'],
            '_regular_price' => '10.00',
            '_sale_price' => '5.00',
            '_thumbnail_id' => 10
            // other wp_postmeta product meta values...
        ]);

        $category = ProductCategory::create([
            'cat_name' => 'Test'
        ]);

        $product->categories()->save($category);

How can I create a product and attach a category to it, please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions