2017-05-04 35 views
1

我做了一個簡單的插件是什麼使用戶一步一步選擇,選擇他想要的產品。它使用4個步驟,其中3個是屬性選擇。現在我遇到的問題是直接鏈接需要variation_id。 生成的鏈接產品:以下鏈接WooCommerce - 添加到購物車沒有變化編號

/cart/?add-to-cart=3772&attribute_pa_izmers=20&attribute_pa_forma=kaste&attribute_pa_krasas=spilgtas 

爲了工作,我也需要通過variation_id。但是,如果不手動傳遞每個variation_id組合,我無法找到獲取它的方法。是否有一個鉤子/動作可以用來根據我傳遞的屬性獲取變體ID?或者將產品添加到購物車而不傳遞變化ID?

我已經問過woocommerce論壇,但無濟於事。

在此先感謝。

回答

1

您可以從WC_Ajax::get_variation()方法中借用一些代碼,因爲它在您使用時選擇正常變量產品的屬性。

$data_store = WC_Data_Store::load('product'); 
$variation_id = $data_store->find_matching_product_variation($variable_product, wp_unslash($_POST)); 

需要WooCommerce 3.0+

相關問題