我只是想在一个简单的woocommerce产品上设置产品属性。</ p>
这是我尝试过的:
wp_set_object_terms( $product_ID, 'tekst på mit skilt', text1, False );
该属性的slug是text1,我需要将其设置为:tekstpåmitskilt
我做错了什么,因为它没有设定?
我正在使用此代码创建产品:
add_action('wp_loaded', 'customcart');
function customcart() {
if (isset($_POST["addcustomcarts"])) {
global $woocommerce;
$my_post = array(
'post_title' => $_POST["textInput"],
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_type' =>'product'
);
// Insert the post into the database
$product_ID = wp_insert_post( $my_post );
if ( $product_ID ){
wp_set_object_terms( $product_ID, 'design-selv-skilte', 'product_cat' );
add_post_meta($product_ID, '_regular_price', 100 );
add_post_meta($product_ID, '_price', 100 );
add_post_meta($product_ID, '_stock_status', 'instock' );
add_post_meta($product_ID, '_sku', 'designselvskilt' );
add_post_meta($product_ID, '_visibility', 'hidden' );
//wp_set_object_terms( $product_ID, 'tekst på mit skilt', text1, False );
$woocommerce->cart->add_to_cart( $product_ID, $quantity=1 );
exit( wp_redirect( '/kurv' ) );
}
}
}