Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EricBusch/a2b66cb138b874a7cc291e8b5a6d1f3f to your computer and use it in GitHub Desktop.
Save EricBusch/a2b66cb138b874a7cc291e8b5a6d1f3f to your computer and use it in GitHub Desktop.
Import a product's image during a Product Set import/update instead of after the product is imported. Use with CAUTION. This may cause product imports to be drastically slower or fail. [datafeedr]
<?php
/**
* Import a product's image during a Product Set import/update instead
* of after the product is imported.
*
* Use with CAUTION. This may cause product imports to be drastically slower or fail.
*
* @see do_action_ref_array(), get_post()
*
* @param array $post An array of post data including ID, post_title, post_status, etc...
* @param array $product An array of product data returned from the Datafeedr API.
* @param array $set A post array for this Product Set with an array key of postmeta containing all post meta data.
* @param string $action The action the Product Set is performing. Value are either "insert" or "update".
*/
add_action( 'dfrpswc_do_product', 'mycode_process_image_on_import', 20, 4 );
function mycode_process_image_on_import( $post, $product, $set, $action ) {
if ( $action == 'insert' || $action == 'update' ) {
$object = get_post( $post['ID'] );
do_action_ref_array( 'the_post', array( &$object ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment