0

我想在前端展示 Woocommerce 的原生 CSV 产品导入工具,以便具有某些角色(供应商)的用户可以使用它来将他们的产品上传到网站。

自从它出现在 3.0 更新中以来,我从未使用过原生的 Woocommerce 导入器,但我知道我应该如何开始。

在 WC 文档中我找到了 WC_Product_CSV_Importer 类,在里面我找到了方法:Initialize importer

    Initialize importer.

    __construct( string $file, array $params = array()  )


    Parameters
        $file  --> File to read.
        $params  --> Arguments for the parser.

和方法:读取文件

Read file

read_file( )

我还认为,如果我找到产品进口商 metabox,我可以使用它。

有没有人试图做类似的事情?

任何意见都很受欢迎

Woocommerce 类:https ://docs.woocommerce.com/wc-apidocs/class-WC_Product_CSV_Importer.html

4

1 回答 1

0

Woocommerce Rest API 使您能够为用户提供从网站前端发布新产品的能力。

批量创建、更新和删除多个产品

<?php
$data = [
'create' => [
    [
        'name' => 'Woo Single #1',
        'type' => 'simple',
        'regular_price' => '21.99',
        'virtual' => true,
        'downloadable' => true,
        'downloads' => [
            [
                'name' => 'Woo Single',
                'file' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg'
            ]
        ],
        'categories' => [
            [
                'id' => 11
            ],
            [
                'id' => 13
            ]
        ],
        'images' => [
            [
                'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg',
                'position' => 0
            ]
        ]
    ],
    [
        'name' => 'New Premium Quality',
        'type' => 'simple',
        'regular_price' => '21.99',
        'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
        'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
        'categories' => [
            [
                'id' => 9
            ],
            [
                'id' => 14
            ]
        ],
        'images' => [
            [
                'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
                'position' => 0
            ],
            [
                'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
                'position' => 1
            ]
        ]
    ]
],
'update' => [
    [
        'id' => 799,
        'default_attributes' => [
            [
                'id' => 6,
                'name' => 'Color,
                'option' => 'Green'
            ],
            [
                'id' => 0,
                'name' => 'Size',
                'option' => 'M'
            ]
        ]
    ]
],
'delete' => [
    794
]
];

print_r($woocommerce->post('products/batch', $data));
?>
于 2018-05-24T06:56:31.350 回答