Created
July 1, 2015 19:43
-
-
Save vimes1984/532347bea69ec183c2f4 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
| public function addattribute($csvvalue, $attvalue, $attname, $position){ | |
| $attheight = get_term_by( 'name', $csvvalue, $attvalue ); | |
| if(!$attheight){ | |
| $attheightnew = wp_insert_term( $csvvalue, $attvalue); | |
| $attheightnewtest = get_term_by( 'id', $attheightnew['term_id'], $attvalue ); | |
| $product_attributes = array( | |
| //Make sure the 'name' is same as you have the attribute | |
| 'name' => $attvalue, | |
| 'value' => $csvvalue, | |
| 'position' => $position, | |
| 'is_visible' => 1, | |
| 'is_variation' => 0, | |
| 'is_taxonomy' => 1, | |
| ); | |
| echo "doesn't exist.. </br>"; | |
| echo "<pre>"; | |
| var_dump($attheightnewtest); | |
| var_dump($attheightnewget); | |
| echo "</pre>"; | |
| wp_set_object_terms( $post_id, $attheightnewtest->term_id, $attvalue ); | |
| }else{ | |
| //Type attribute | |
| $product_attributes = array( | |
| //Make sure the 'name' is same as you have the attribute | |
| 'name' => $attvalue, | |
| 'value' => $csvvalue, | |
| 'position' => $position, | |
| 'is_visible' => 1, | |
| 'is_variation' => 0, | |
| 'is_taxonomy' => 1, | |
| ); | |
| wp_set_object_terms( $post_id, $attheight->term_id, $attvalue ); | |
| } | |
| return $product_attributes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment