Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pietromalerba/47a94b18f11c7c6d40dd to your computer and use it in GitHub Desktop.
Save pietromalerba/47a94b18f11c7c6d40dd to your computer and use it in GitHub Desktop.
<?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