necesito crear un Producto (Simple o Variable), para eso necesito que este producto tenga algo Variaciones preconfiguradas de acuerdo con la categoria de producto.
Por ejemplo: Si agrego un Tenis Nike producto con el Ropa categoría, la Variación de género aparecería configurado con valores Macho femenino; y así.
Intenté con este código, pero sin éxito.
$product_factory = new WC_Product_Factory();
// Get Product id
$product_id = $product_factory->get_product( $post_id );
if ( $product_cat_id === 534 )
{
// Create attribute for object
$attribute = new WC_Product_Attribute();
$attribute->set_id(0);
$attribute->set_name('slug_product');
$attribute->set_options(array( ''));
$attribute->set_position(0);
$attribute->set_visible(1);
$product_id->set_attributes(array($attribute));
$id = $product_id->save();
}
Cualquier respuesta seria de gran ayuda.
.