Forked from EricBusch/add-custom-promo-attribute.php
Last active
August 29, 2015 14:08
-
-
Save pietromalerba/47a94b18f11c7c6d40dd 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