Skip to content

Instantly share code, notes, and snippets.

@pietromalerba
Forked from EricBusch/add-color-attribute.php
Last active August 29, 2015 14:08
Show Gist options
  • Save pietromalerba/584f45e85e1c4cec997b to your computer and use it in GitHub Desktop.
Save pietromalerba/584f45e85e1c4cec997b to your computer and use it in GitHub Desktop.
<?php
/**
* Add color attribute.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_color_attribute', 20, 6 );
function mycode_add_color_attribute( $value, $attribute, $post, $product, $set, $action ) {
if ( $attribute == 'pa_color') {
if ( isset( $product['color'] ) ) {
$value = $product['color'];
}
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment