[英]WooCommerce add order admin hook for recalculate button
在實際提交訂單之前,我希望在管理中循環添加到訂單中的所有產品。 到目前為止,我發現的唯一 WooCommerce 掛鈎僅允許您單獨訪問產品項目。
我正在尋找一個鈎子,當用戶點擊重新計算按鈕時會觸發,但實際上它可以在用戶添加產品、稅金、運輸方式等時觸發。我只需要循環到目前為止添加到訂單中的所有項目.
目前我正在使用woocommerce_admin_order_item_values
掛鈎,但它是一個自包含循環,因此不允許我將所有 '$item['product_id']' 添加在一起。
function action_woocommerce_admin_order_item_values( $null, $item, $absint ) {
$item_ids = array($item['product_id']);
}
add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 );
您也可以使用 - woocommerce_before_order_itemmeta
Hook 但這只能單獨訪問每個項目,而我需要遍歷摘要中的每個項目。
當您單擊“重新計算”按鈕時,WooCommerce 提供了許多掛鈎。 我在這里列出了這些鈎子,這取決於您根據您的要求在其中進行選擇。
$order = WC_Order 對象
add_action("woocommerce_order_before_calculate_taxes", "custom_order_before_calculate_taxes", 10, 2);
function custom_order_before_calculate_taxes($args, $order) {
// Do something
}
add_action("woocommerce_order_item_after_calculate_taxes", "custom_order_item_after_calculate_taxes", 10, 2);
function custom_order_item_after_calculate_taxes($order, $calculate_tax_for) {
// Do something
}
add_action("woocommerce_before_order_object_save", "custom_before_order_object_save", 10, 2);
function custom_before_order_object_save($order, $data_store) {
// Do something
}
add_action( 'woocommerce_order_before_calculate_totals', "custom_order_before_calculate_totals", 10, 2);
function custom_order_before_calculate_totals($and_taxes, $order ) {
// Do something
}
add_action( 'woocommerce_order_after_calculate_totals', "custom_order_after_calculate_totals", 10, 2);
function custom_order_after_calculate_totals($and_taxes, $order) {
//Do something
}
add_filter("woocommerce_order_is_vat_exempt", function(){
return $boolean;
});
add_filter("woocommerce_order_get_total", "custom_order_get_total", 10, 2);
function custom_order_get_total($value, $order) {
//do somethig
return $value;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.