-1

我想从 URL 将产品导入 word-press。

我想完全了解产品表,我的意思是我想将我的 URL 表映射到 woo commerce 表。woo commerce 中的产品和属性以及价格和变量表是什么?

例如

 INSERT INTO `catalog_product_website` (`product_id`, `website_id`) VALUES  
4

1 回答 1

2

Wordpress Woocommerce 将产品信息存储在wp_post(post_type = product) 和wp_postmeta(meta_key and meta_value for a post_id) 中。

因此,要以这种方式存储新产品,您必须执行以下操作:

wp_post中添加新产品:

$post = array(
    'post_author' => $user_id,
    'post_content' => '',
    'post_status' => "publish",
    'post_title' => $product->part_num,
    'post_parent' => '',
    'post_type' => "product",
);

//Create post
$post_id = wp_insert_post( $post, $wp_error );
if($post_id){
    $attach_id = get_post_meta($product->parent_id, "_thumbnail_id", true);
    add_post_meta($post_id, '_thumbnail_id', $attach_id);
}

设置新产品的类别和类型

wp_set_object_terms( $post_id, 'Races', 'product_cat' );
wp_set_object_terms($post_id, 'simple', 'product_type');

然后将其值设置为wp_postmeta

update_post_meta( $post_id, '_visibility', 'visible' );
update_post_meta( $post_id, '_stock_status', 'instock');
update_post_meta( $post_id, 'total_sales', '0');
update_post_meta( $post_id, '_downloadable', 'yes');
update_post_meta( $post_id, '_virtual', 'yes');
update_post_meta( $post_id, '_regular_price', "1" );
update_post_meta( $post_id, '_sale_price', "1" );
update_post_meta( $post_id, '_purchase_note', "" );
update_post_meta( $post_id, '_featured', "no" );
update_post_meta( $post_id, '_weight', "" );
update_post_meta( $post_id, '_length', "" );
update_post_meta( $post_id, '_width', "" );
update_post_meta( $post_id, '_height', "" );
update_post_meta( $post_id, '_sku', "");
update_post_meta( $post_id, '_product_attributes', array());
update_post_meta( $post_id, '_sale_price_dates_from', "" );
update_post_meta( $post_id, '_sale_price_dates_to', "" );
update_post_meta( $post_id, '_price', "1" );
update_post_meta( $post_id, '_sold_individually', "" );
update_post_meta( $post_id, '_manage_stock', "no" );
update_post_meta( $post_id, '_backorders', "no" );
update_post_meta( $post_id, '_stock', "" );

希望能帮助到你。

来源:如何使用 php 代码在 woocommerce 中添加产品

于 2016-07-17T08:29:47.130 回答