でプログラム製品の種類を挿入することができます製品タイプを設定していません。
製品の追加オプションから管理者と同じように、product_typeを更新または挿入する必要があります。
事前にこのお手伝いをお願いします。
でプログラム製品の種類を挿入することができます製品タイプを設定していません。
製品の追加オプションから管理者と同じように、product_typeを更新または挿入する必要があります。
事前にこのお手伝いをお願いします。
チェックした例:
// An array of IDs of categories we to add to this post.
$cat_ids = array(6, 8);
/*
* If this was coming from the database or another source, we would need to make sure
* these were integers:
$cat_ids = array_map('intval', $cat_ids);
$cat_ids = array_unique($cat_ids);
*/
// Add these categories, note the last argument is true.
$term_taxonomy_ids = wp_set_object_terms(42, $cat_ids, 'category', true);
if (is_wp_error($term_taxonomy_ids)) {
// There was an error somewhere and the terms couldn't be set.
} else {
// Success! These categories were added to the post.
}
私はあなたがアクションを使用せずに直接コードを書いていると思います。
私は私は私が私の機能に
register_taxonomy('product_type', array('product_type'));
として分類を登録する必要が溶液(ユーザ定義)を得、これは
あなたは正しいですが、私が行動を加えても機能していません。 – ngulhane02
そして、もしそれが働くのであれば、製品をロードするのに3倍の時間を要します。 – ngulhane02
注:この機能は、製品を動的に作成する場合、またはidを使用して製品のタイプを変更する必要がある場合に使用できます。私は、これをどのように実装する必要があるかについてのアイデアを得るための答えを追加しました。 – Nikhil
を役に立てば幸い
function woo_set_type(){
// Your code
$result = wp_set_object_terms($product_id, 'simple','product_type');
}
add_action('init', 'woo_set_type');
、これを試してみてくださいfunction.phpを呼び出してから
wp_set_object_terms($product_id, 'grouped', 'product_type', false);
したがって、グループ化/変数/外部/単純として渡すときに製品タイプが作成されます。
タクソノミー 'product_type'が既に存在するため、この方法は適切ではありません。 – Nikhil
カテゴリタクソノミーではなくproduct_typeタクソノミーを使用しています。 – ngulhane02