[英]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.