如何使用php代码将woocommerce产品添加到自定义Product_type?
问题描述:
WooCommerce产品易于创建,但该产品已添加到product_type:简单。我想将产品添加到:如何使用php代码将woocommerce产品添加到自定义Product_type?
static function createTicket($postId, $productDetails) {
$id = wp_insert_post(array(
'post_type' => 'product',
'post_title' => $productDetails['title'],
'post_content' => $productDetails['description'],
'post_status' => get_post_status($postId),
'max_value' => 1,
));
update_post_meta($id, '_price', $productDetails['price']);
update_post_meta($id, '_regular_price', $productDetails['price']);
update_post_meta($id, '_wpws_testID', $postId);
update_post_meta($id, '_sold_individually', "yes");
wp_set_object_terms($id, 'test', 'product_type');
return $id;
}
我已经加入
wp_set_object_terms “定制产品类型测试”($ ID, '测试', '产品类型');
但没有任何工程
答
// add a product type
add_filter('product_type_selector', 'add_custom_product_type');
function add_custom_product_type($types){
$types[ 'test_custom_product_type' ] = __('test Product');
return $types;
}
编辑
请检查下面的链接它HEL p你更多关于这个
http://jeroensormani.com/adding-a-custom-woocommerce-product-type/
https://wisdmlabs.com/blog/create-product-type-custom-settings-woocommerce/
编辑
以上代码的旧版本WooCommerce
0123的使用此代码可以保存具有自定义产品类型的产品。它与WooCommerce 3. * 检查工作为这我已与这些步骤完成更多的信息https://gist.github.com/stirtingale/753ac6ddb076bd551c3261007c9c63a5
function register_simple_rental_product_type() {
class WC_Product_Simple_Rental extends WC_Product {
public function __construct($product) {
$this->product_type = 'simple_rental';
parent::__construct($product);
}
}
}
add_action('init', 'register_simple_rental_product_type');
function add_simple_rental_product($types){
// Key should be exactly the same as in the class
$types[ 'simple_rental' ] = __('Simple Rental');
return $types;
}
add_filter('product_type_selector', 'add_simple_rental_product');
。自定义产品类型显示在product_type下拉菜单下。现在我想将一个新产品分配给后端的自定义产品类型 – Himani
我该如何实现这一目标? – Himani
@Himani不遵循你所说的话? –