0
votes

The file email-order-items.php has the following line of code:

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

The following action hook has been added to a plugin I am using (Woocommerce Composite Products):

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

I would like to override the function wc_cp_order_item_subtotal to change the way to item subtotal is displayed. I have tried adding the following to my child theme functions.php, but it doesn't do anything.

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';
}

Any tips to help me get this working would be greatly appreciated.

1

1 Answers

1
votes

It isn't mentioned in the Codex, but I usually call the remove_action() function from a hook.

Also, as covered in the Codex example for action added from classes, you need to access the class instance or variable.

I don't see wc_cp_order_item_subtotal in the Composite plugin anywhere, so I presume you aren't using Woo's version. In which case, I don't have access to the code and can't tell you exactly how to access the class variable.

But if you were using Woo's Composite Products it would be as follows:

Edited for Composites 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');