Skip to content

Instantly share code, notes, and snippets.


danielimmke/functions.php Secret

Created Dec 9, 2017
What would you like to do?
// Maps core part numbers to force sell after importing is finished.
add_action('pmxi_after_xml_import', 'danieldo_core_fees', 10, 1);
function danieldo_core_fees($post) {
// Grab every product that was imported with a core fee
$core_query = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
'key' => 'core_fee',
'value' => '',
'compare' => '!=',
) );
$products = $core_query->posts;
foreach ($products as $product) {
$core_id = get_post_meta($product->ID, 'core_fee', true);
// Grab a post object by the core fee ID
$core_fee = get_page_by_title( strval($core_id), OBJECT, 'product' );
// Add the ID to a special custom field for the Force Sells plugin.
add_post_meta($product->ID, '_force_sell_synced_ids', array($core_fee->ID), true);
// Disable visibiity on core fees so they won't show up where they aren't supposed to by default.
wp_set_object_terms( $core_fee->ID, array('exclude-from-catalog', 'exclude-from-search'), 'product_visibility', true );
// Remove original custom field to keep things tidy
delete_post_meta($product->ID, 'core_fee');
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment