2014-09-24 3 views
0

파일 이메일 주문 items.php는 다음 코드 줄을 가지고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에 설명 된대로 클래스 인스턴스 또는 변수에 액세스해야합니다.

어디서나 Composite 플러그인에 wc_cp_order_item_subtotal이 표시되지 않으므로 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 Composite Product 플러그인을 사용하고 있지만 버전 2.4.0에서 코드를 리팩토링하고 BTO에 대한 참조를 제거한 것처럼 보입니다. $ woocommerce_bto-> order-> woocommerce_bto와 동일한 기능을 수행하려면 어떻게해야합니까? –

+1

'bto'가 'cp'가되었고 'woo'가 'wc'가 된 것처럼 보입니다. 그래서 전체 플러그인의 전역 변수는'$ woocommerce_composite_products'이고'WC_CP_Order()'클래스는 주 클래스의'order' 변수로 초기화되어 있으므로'$ woocommerce_composite_product-> order'가됩니다. 나는 그 여분의'woocommerce_bto'를 어디에서 가져 왔는지 모르겠다. 아마도 복사/붙여 넣기가 실패 할 것이다. – helgatheviking

+0

그것이 작동합니다 - 대단히 감사합니다! –

관련 문제