WooCommerce Product Primary Image

Completado Publicado Oct 29, 2014 Pagado a la entrega
Completado Pagado a la entrega

I have a WordPress website using Woocommerce. I need to attach images to products automatically when uploaded through the Add Media. At the moment I have the following code:

add_action('add_attachment', function( $attachmentID ) {

if ( ! class_exists( 'WC_Product' ) ) return; // if no WooCommerce do nothing

// an attachment was jus saved, first of all get the file name

$src = wp_get_attachment_image_src( $attachmentID, 'full' );

$filename = pathinfo( $src[0], PATHINFO_FILENAME );

// now let's see if exits a product with the sku that match filename

$args = array(

'meta_key' => '_sku',

'meta_value' => $filename,

'post_type' => 'product',

'posts_per_page' => '1' // assuming sku is unique get only one post

);

$prods = get_posts( $args );

if ( ! empty($prods) ) {

// ok we have a match, exists a product having sku that match filename

$product = array_pop( $prods );

// set the thumbnail for the product

set_post_thumbnail( $product, $attachmentID );

// now "attach" the post to the product setting 'post_parent'

$attachment = get_post( $attachmentID );

$attachment->post_parent = $product->ID;

wp_update_post( $attachment );

}

});

It takes the name of the image and automatically attaches to the product with the matching SKU. For example [url removed, login to view] becomes automatically the Main Product Image of the product having the SKU set as 45rt10.

The problem is that is only working with products who are set as Simple Product. Variations (each having a unique SKU) - children of a Variable Product - is not having the images attached.

I need someone to start and finish today.

PHP WordPress

Nº del proyecto: #6657974

Sobre el proyecto

8 propuestas Proyecto remoto Activo Oct 29, 2014

Adjudicado a:

fparekh

HI Steve, as per our discussion on skype i have edited my bid. and i am done with you project. looking forward. Michael

€100 EUR en 1 día
(29 comentarios)
5.8

8 freelancers están ofertando un promedio de €42 por este trabajo

CreativeB24

A proposal has not yet been provided

€21 EUR en 1 día
(24 comentarios)
6.6
NostroDev

A proposal has not yet been provided

€23 EUR en 1 día
(147 comentarios)
6.6
herpay

Hello, I'm an experienced wordpress developer and familar with woocommerce. I can modify the automatic image attaching in such a way that it also works for product variations. I can make it within max a day after yo Más

€22 EUR en 1 día
(139 comentarios)
5.6
freelancer0080

A proposal has not yet been provided

€70 EUR en 2 días
(14 comentarios)
4.5
elegantic

Greetings, we are a team of dedicated professionals along with several years of experience in this field and provide original work. We have reviewed your requirements , have check your attachment and are ready to work Más

€277 EUR en 1 día
(9 comentarios)
4.1
securetechs

I will fix it in next 2 to 3 hours . Please give me admin details for this site and ftp . No worry it will be fixed as per your desire . Thanks in advance . Best Regards

€34 EUR en 1 día
(35 comentarios)
3.8
softbyteindore

Hello we are in team having 2000+ hours of experience please come on chat to discuss more about the project to do this work in quick time. we can start and end this work asap. Thanks softbyteinfotech

€30 EUR en 1 día
(1 comentario)
0.8