[英]Hide Add to Cart button in Woocommerce product variations for a specific attribute value
[英]woocommerce: product attribute will not add value
我正在以編程方式創建屬性變體(可變產品)。 我所看到的一切都很容易做到這一點,但價值根本沒有出現。 這是我的代碼:
$thedata = Array(
'pa_performance_dates' => Array(
'name' => 'pa_performance_dates',
'value' => $arrayOfTermIDs,
'position' => 1,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
)
);
update_post_meta( $product_id, '_product_attributes', $thedata );
屬性:“演出日期”工作
屬性值(屬性下的術語):“1571986800”工作
在產品 ID 下添加的屬性值:不工作
我已經嘗試了所有方法:將上面的 VALUE 設置為術語 slugs 的數組、ID 的數組、ID 或 slug/值的簡單字符串。 沒有任何效果。 我也關注了這些 stackoverflow 問題:
woocommerce:為產品屬性添加價值
創建 WooCommerce 產品變體會添加一個空屬性值
為 Woocommerce 中的產品添加帶有值的產品屬性
我還測試了 product_id 變量,它正確顯示了帖子的 ID。
我究竟做錯了什么?????!?
要為產品的屬性添加價值,請使用wp_set_object_terms
例如: $arrayOfTermIDs = array( 'Test1', 'Test2', 'Test3' );
foreach ($arrayOfTermIDs as $arrayOfTermID) {
$term_taxonomy_ids = wp_set_object_terms( $product_id, $arrayOfTermID, 'pa_performance_dates', true );
}
對於 append 值,將最后一個參數設置為true
或將其設置為false
以覆蓋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.