2017-05-13 7 views
0

Hallo ich jetzt für eine Weile gesucht, aber ich kann dies funktioniert, ich kann die Kategorie von Namen bekommen, und auch zu einem programmatisch i cantGet WooCommerce Kategorie mit Namen und asign zur Produkt

$product = new WC_Product(4); 
write_log($product->get_title()); 

// Gets term object from Tree in the database. 
$category = get_term_by('name', 'bolsas', 'product_cat'); 
echo "Cat: ".$category->name; 

wp_set_object_terms($product->id, $cat->term_id, 'product_cat'); 
asign Produkt

Im Ausführen dieser auf functions.php-Datei und das Neuladen der Seite, ich habe auch eine Funktion, sich in der Konsole für das Debugging anzumelden, aber es bringt mich nirgendwohin.

Bitte helfen!

Antwort

0

dies, weil in Thema functions.php WooCommerce Taxonomien Versuchen

$tag = '5'; // Wrong. This will add the tag with the *name* '5'. 
$tag = 5; // Wrong. This will also add the tag with the name '5'. 
$tag = array('5'); // Wrong. Again, this will be interpreted as a term name rather than an id. 

$tag = array(5); // Correct. This will add the tag with the id 5. 
wp_set_post_terms($post_id, $tag, $taxonomy); 
Verwandte Themen