Created
September 1, 2017 15:33
-
-
Save EricBusch/e5e1622c9a91f7b9f4cb57d6f9a7830d to your computer and use it in GitHub Desktop.
Prevent the price of a product from being overridden during a Product Set update. [datafeedr][dfrpswc]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prevent the price of a product from being overridden during a Product Set update. | |
* | |
* This code will allow the product's price to be imported when the product is first imported but | |
* upon all subsequent Product Set updates, the product's price will not be updated. Instead it will | |
* rely on the price already in the database. | |
* | |
* @param array $meta An array containing postmeta data for this $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". | |
* | |
* @return array Updated $meta array. | |
*/ | |
add_filter( 'dfrpswc_filter_postmeta_array', 'mycode_prevent_product_price_override', 20, 5 ); | |
function mycode_prevent_product_price_override( $meta, $post, $product, $set, $action ) { | |
// Do nothing if we are inserting the product for the first time. | |
if ( 'insert' == $action ) { | |
return $meta; | |
} | |
// Since we are updating the product, ignore all pricing information. | |
unset( $meta['_price'] ); | |
unset( $meta['_regular_price'] ); | |
unset( $meta['_sale_price'] ); | |
return $meta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment