WooCommerce Attachment [RESOLVED]

Hey there!
So I have been having issues with the Post Creation add-on in regards to attaching images. The images get uploaded but they aren’t being related to Product Post properly. So I am having to use some duct tape and anger.

Below is what I have gotten so far, but am still hitting a wall. I am able to make the Attachment Post, relate it to the Parent Post, but it is still not showing on the WooCommerce Product. Any ideas on where I am going wrong?

add_action( 'gform_advancedpostcreation_post_after_creation_1', 'gaws_update_product_information', 10, 4 );
function gaws_update_product_information( $post_id, $feed, $entry, $form ){

    $results  = preg_match_all("/\[([^\]]*)\]/", $entry[4], $matches);
    $images = explode( ",", $matches[1][0] );
	foreach( $images as $i ){
		$file = stripslashes($i);
		$img = str_replace( '"', '', $file);

		$args = array(
			'guid'           => $file, 
			'post_mime_type' => get_mime_type( $img ),
			'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $file ) ),
			'post_content'   => '',
			'post_status'    => 'inherit'

		wp_insert_attachment( $args, $file, $post_id );

Solved, you can close this @chrishajer

1 Like