当我在 Woocommerce 中为我的可变产品创建 2 个属性时,几乎所有东西都可以正常工作。 只有可变产品没有选择默认值。 (见图片) 我不明白如何让默认属性附加到我的可变产品名称上。有人有线索吗? 数据是通过 Mariadb 查询选择的
update_post_meta( $post_id, '_manage_stock', 'no');
$parent_id = $post_id;
$variation = array(
'post_title' => $descriptionnlstrip,
'post_content' => $descriptionfull,
'post_status' => 'publish',
'post_parent' => $parent_id,
'post_type' => 'product_variation',
);
$sql2 = "SELECT DISTINCT `$col5`, `$col3` from `$exporttabel` WHERE `$col37`LIKE '$descriptionnlstrip%' ORDER BY `$col5`+0";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
$count2++;
while($row2 = $result2->fetch_assoc()) {
wp_set_object_terms( $parent_id, $row2["$col5"], 'pa_size', true );
wp_set_object_terms( $parent_id, $row2["$col3"], 'pa_color', true );
$thedata = Array(
'pa_size' => Array(
'name'=>'pa_size',
'value'=>$row2["$col5"],
'postion' => $count2,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1',
),
'pa_color' => Array(
'name'=>'pa_color',
'value'=>$row2["$col3"],
'postion' => $count2,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1',
)
);
update_post_meta($parent_id,'_product_attributes',$thedata);
}
}
$variation_id = wp_insert_post( $variation );
update_post_meta( $variation_id, '_regular_price', $sellingprice );
update_post_meta( $variation_id, '_price', $sellingprice );
update_post_meta( $variation_id, '_sale_price', "" );
update_post_meta( $variation_id, 'attribute_' . 'size', $size );
update_post_meta( $variation_id, 'attribute_' . 'color', $color );
update_post_meta( $variation_id, '_manage_stock', 'yes');
update_post_meta( $variation_id, "_stock", $availstock);
update_post_meta( $variation_id, '_short_description', $descriptionfull);
update_post_meta( $variation_id, '_variation_description', $quality);
update_post_meta( $variation_id, '_visibility', 'visible' );
update_post_meta( $variation_id, '_stock_status', 'instock');
update_post_meta( $variation_id, 'total_sales', '0');
update_post_meta( $variation_id, '_downloadable', 'no');
update_post_meta( $variation_id, '_virtual', 'no');
update_post_meta( $variation_id, '_purchase_note', "bedankt voor de koop" );
update_post_meta( $variation_id, '_featured', "no" );
update_post_meta( $variation_id, '_weight', $weightinkg );
update_post_meta( $variation_id, '_length', $length );
update_post_meta( $variation_id, '_width', $width );
update_post_meta( $variation_id, '_height', $height );
update_post_meta( $variation_id, '_sku', $productcode);
update_post_meta( $variation_id, '_product_attributes', array());
update_post_meta( $variation_id, '_sale_price_dates_from', "" );
update_post_meta( $variation_id, '_sale_price_dates_to', "" );
update_post_meta( $variation_id, '_sold_individually', "" );
update_post_meta( $variation_id, '_backorders', "no" );
WC_Product_Variable::sync( $parent_id );
我尽可能地尝试了。尝试修复是 2 天。 试图将字段更改为 slug 或名称,我尝试了 pa_size 或 pa_color