fixed bug where woocommerce_create_term would return notice Trying to get property of non-object if $term was null

This commit is contained in:
Nathaniel Schweinberg 2012-08-24 22:08:18 -05:00
parent 251bbe75d1
commit 7dc04f5a2f
1 changed files with 14 additions and 9 deletions

View File

@ -316,17 +316,22 @@ function woocommerce_create_term( $term_id, $tt_id, $taxonomy ) {
$term = get_term($term_id, $taxonomy); $term = get_term($term_id, $taxonomy);
// gets the sibling terms if ( $term != null ){
$siblings = get_terms($taxonomy, "parent={$term->parent}&menu_order=ASC&hide_empty=0");
// gets the sibling terms
foreach ($siblings as $sibling) { $siblings = get_terms($taxonomy, "parent={$term->parent}&menu_order=ASC&hide_empty=0");
if( $sibling->term_id == $term_id ) continue;
$next_id = $sibling->term_id; // first sibling term of the hierarchy level foreach ($siblings as $sibling) {
break; if( $sibling->term_id == $term_id ) continue;
$next_id = $sibling->term_id; // first sibling term of the hierarchy level
break;
}
// reorder
woocommerce_order_terms( $term, $next_id, $taxonomy );
} }
// reorder
woocommerce_order_terms( $term, $next_id, $taxonomy );
} }