Woocommerce覆盖插件操作

时间:2014-09-24 16:36:59

标签: wordpress woocommerce

文件email-order-items.php包含以下代码行:

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

以下操作挂钩已添加到我正在使用的插件中(Woocommerce Composite Products):

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 个答案:

答案 0 :(得分:1)

在Codex中没有提到,但我通常从钩子中调用remove_action()函数。

此外,如从类添加的Codex example中所述,您需要访问类实例或变量。

我无法在任何地方看到复合插件中的wc_cp_order_item_subtotal,所以我认为你并没有使用Woo的版本。在这种情况下,我无法访问代码,无法准确地告诉您如何访问类变量。

但如果你使用的是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');
相关问题