問題描述
我想新增一個新的自定義”product type” 到 woocommerce 外掛:
嘗試將當前存在的產品型別檔案 (woocommerce template structure)中的一個複製為新檔案 (檔名和內部註釋的名稱),但不能工作!
最佳解決辦法
新增到購物車模板只是您需要做的許多事情之一。每個產品型別都有它自己的類在/includes/資料夾。每個擴充套件 WC_Product 類。
要將列表中的專案新增到篩選 (在管理方面),而不是 front-end,與 add-to-cart.php 模板不同,您需要對 product_type_selector 進行過濾。
add_filter( 'product_type_selector', 'wpa_120215_add_product_type' );
function wpa_120215_add_product_type( $types ){
$types[ 'your_type' ] = __( 'Your Product Type' );
return $types;
}
那麼你需要宣告你的產品類。標準命名系統是 WC_Product_Type_Class,所以在這個例子中它將是:
class WC_Product_Your_Type extends WC_Product{
/**
* __construct function.
*
* @access public
* @param mixed $product
*/
public function __construct( $product ) {
$this->product_type = 'your_type';
parent::__construct( $product );
}
}
你問一個非常複雜的問題,我無法提供更完整的答案。希望這將使您在正確的道路上。我強烈建議您閱讀 WooCommerce 中的程式碼。評論很好,您可以看到他們如何處理不同的產品型別。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。

