2014-09-24 125 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