Created
September 11, 2022 20:07
-
-
Save cdsaenz/8e719ed922f2b3d77ee8ae4e44e4d402 to your computer and use it in GitHub Desktop.
Wordpress create product woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create product | |
*/ | |
function csdev_new_simple_product() | |
{ | |
$product = new WC_Product_Simple(); | |
$product->set_name('test 2'); | |
$product->set_sku('test2'); | |
$product->set_slug('test2-product'); | |
$product->set_regular_price(0.00); | |
$product->set_short_description('<p>Test Product</p>'); | |
$product->set_description('Long Test Product...'); | |
$product->set_image_id(90); | |
// let's suppose that our 'Accessories' category has ID = 19 | |
$product->set_category_ids(array(19)); | |
$product->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment