Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Last active January 5, 2018 14:43
Show Gist options
  • Save EricBusch/4aeac50a9c1c4335e1f40673fc76f9a9 to your computer and use it in GitHub Desktop.
Save EricBusch/4aeac50a9c1c4335e1f40673fc76f9a9 to your computer and use it in GitHub Desktop.
Add '_pricemesh_pids' during product set inserts and updates. [datafeedr][dfrps][dfrpswc]
<?php
/**
* Add '_pricemesh_pids' during product set inserts and updates.
*
* @param array $meta An array containing postmeta data for this $post.
* @param array $post Array containing WordPress Post information.
* @param array $product Array containing Datafeedr Product information.
* @param array $set Array containing Product Set information.
* @param string $action Either "update" or "insert" depending on what the Product Set is doing.
*
* @return array Updated $meta array.
*/
function mycode_add_pricemesh_pids( $meta, $post, $product, $set, $action ) {
// Define barcode fields to use here.
$fields = array( 'ean', 'upc', 'isbn' );
$pids = array();
foreach ( $fields as $field ) {
if ( isset( $product[ $field ] ) ) {
$pids[] = $product[ $field ];
}
}
if ( ! empty( $pids ) ) {
$meta['_pricemesh_pids'] = implode( ',', $pids );
}
return $meta;
}
add_filter( 'dfrpswc_filter_postmeta_array', 'mycode_add_pricemesh_pids', 20, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment