Dies ist der aktuelle Code, der Produkte erstellt und veröffentlichen, die Bild -ID jedoch nicht mit dem Produkt verknüpft: < /p>
Code: Select all
/* create product on post -- */
add_action( 'publish_post', 'auto_create_product_from_post', 100, 2 );
function auto_create_product_from_post($id, $post){
// Create an empty instance of the WC_Product
$product = new WC_Product_Simple(); // set_name( $post->post_title );
$product->set_status( $post->post_status );
$product->set_description( $post->post_content ); // (optional)
$product->set_short_description( $post->post_excerpt ); // (optional)
$product->set_gallery_image_ids(21741); // sets the 'back of print' example image to product gallery
// $product->set_image_id( xxx ?what variable? xxx ); // the part that's stumping me
// You can use any available WC_Product methods to set other properties
// see: https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html
$product->save(); // Save (publish) new product
}
< /code>
Ich habe es ausprobiert, ohne Erfolg: < /p>
$image = get_post_thumbnail_id( $post->ID );
< /code>
$image = get_attached_media( 'image', $post->ID );