2014-09-24 207 views
0

文件電子郵件階items.php具有下面的代碼行:Woocommerce覆蓋插件操作

echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item)); 

下列行動掛鉤已添加到我使用的插件(Woocommerce複合材料產品):

add_action('woocommerce_order_formatted_line_subtotal', array($this, 'wc_cp_order_item_subtotal'), 10, 3); 

我想覆蓋函數wc_cp_order_item_subtotal來改變項目小計的顯示方式。我曾嘗試將以下內容添加到我的子主題functions.php中,但它沒有做任何事情。

remove_action('woocommerce_order_formatted_line_subtotal', 'wc_cp_order_item_subtotal', 10); 
add_action('woocommerce_order_formatted_line_subtotal', 'child_wc_cp_order_item_subtotal', 10, 3); 

function child_wc_cp_add_order_item_meta($order_item_id, $cart_item_values, $cart_item_key = '') { 
    return 'xxxxxxx'; 
} 

任何提示,以幫助我得到這個工作將不勝感激。

回答

1

Codex沒有提到它,但我通常從掛鉤中調用remove_action()函數。

此外,如Codex example中所述,對於從類添加的操作,您需要訪問類實例或變量。

我看不到wc_cp_order_item_subtotal在Composite插件的任何地方,所以我認爲你沒有使用Woo的版本。在這種情況下,我無法訪問代碼,並且無法準確告訴您如何訪問類變量。

但如果你是使用吳宇森的複合材料產品將是如下:

編輯的複合材料2.4

function so_remove_action(){ 
    global $woocommerce_composite_products; 
    remove_action('woocommerce_order_formatted_line_subtotal', array($woocommerce_composite_products->order, 'wc_cp_order_item_subtotal'), 10, 3); //not sure why it isn't a filter, but also not sure if there is a huge difference 
} 
add_action('init', 'so_remove_action'); 
+0

感謝。我使用官方的Woocommerce複合產品插件,但它看起來像在2.4.0版本中重構了代碼並刪除了對BTO的引用。我如何計算出我的等同於$ woocommerce_bto-> order-> woocommerce_bto的是什麼? – 2014-09-25 11:11:24

+1

它看起來像一切'bto'變成'cp','woo'變成'wc'。所以整個插件的全局變量是'$ woocommerce_composite_products',而'WC_CP_Order()'類被初始化爲主類的'order'變量,因此'$ woocommerce_composite_product-> order'。我不知道從哪裏得到額外的'woocommerce_bto',可能是複製/粘貼失敗。 – helgatheviking 2014-09-25 12:20:43

+0

工作原理 - 非常感謝! – 2014-09-25 12:38:40