如何以编程方式添加产品库图像?

我制作了一个Wordpress-Plugin,可以上传图像,并允许我使用此图像创建Woocommerce产品。

我使用上载的图像来创建产品和产品图像,该图像已经可以使用,但是我似乎找不到找到将更改的版本或其他图片添加为产品库图像的方法。

这是我创建缩略图的方式,已经可以使用了。现在,我还想添加产品库图片。我该怎么做?

$attachment = array(

   'post_mime_type' => $wp_filetype['type'],'post_title'     => sanitize_file_name( $filename ),'post_content'   => '','post_status'    => 'inherit'

);

// Create the attachment

$attach_id = wp_insert_attachment( $attachment,$file,$insert_id );

// Define attachment metadata

$attach_data = wp_generate_attachment_metadata( $attach_id,$file );

// Assign metadata to attachment
                    wp_update_attachment_metadata($attach_id,$attach_data );

// And finally assign featured image to post

set_post_thumbnail( $insert_id,$attach_id );
lihaitomsah1 回答:如何以编程方式添加产品库图像?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3152792.html

大家都在问