Created
February 12, 2014 16:46
-
-
Save EricBusch/8959434 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Add the custom attribute "Special Promotion" to a product. | |
*/ | |
add_filter( 'dfrpswc_product_attributes', 'mycode_add_promo_attribute', 20, 5 ); | |
function mycode_add_promo_attribute( $attributes, $post, $product, $set, $action ) { | |
if ( isset( $product['promo'] ) ) { | |
$attr = 'Special Promotion'; | |
if ( !isset( $attributes[sanitize_title( $attr )] ) ) { | |
$attributes[$attr]['name'] = $attr; | |
} | |
} | |
return $attributes; | |
} | |
/** | |
* Set value for "Special Promotion" attribute. | |
*/ | |
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_set_promo_attribute_value', 30, 6 ); | |
function mycode_set_promo_attribute_value( $value, $attribute, $post, $product, $set, $action ) { | |
if ( isset( $product['promo'] ) ) { | |
$attr = 'Special Promotion'; | |
if ( $attribute == $attr ) { | |
$value = $product['promo']; | |
} | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment