简体   繁体   English

WooCommerce 为重新计算按钮添加订单管理挂钩

[英]WooCommerce add order admin hook for recalculate button

I'm looking to loop over all the products added to an order in the admin before the order is actually submitted.在实际提交订单之前,我希望在管理中循环添加到订单中的所有产品。 So far the only WooCommerce hooks I have found only allow you access the product items individually.到目前为止,我发现的唯一 WooCommerce 挂钩仅允许您单独访问产品项目。

I was looking for a hook that would fire when a user clicks the recalculate button but actually it could trigger when a user adds a product, tax, shipping method, etc.. I just need to loop over all items added to the order so far.我正在寻找一个钩子,当用户点击重新计算按钮时会触发,但实际上它可以在用户添加产品、税金、运输方式等时触发。我只需要循环到目前为止添加到订单中的所有项目.

At the moment I'm using woocommerce_admin_order_item_values hook but it's a self-contained loop so doesn't allow me to add all my '$item['product_id']' together.目前我正在使用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 );

You can also use - woocommerce_before_order_itemmeta Hook but this only accesses each item individually whereas I need to loop over each item in the summary.您也可以使用 - woocommerce_before_order_itemmeta Hook 但这只能单独访问每个项目,而我需要遍历摘要中的每个项目。

There are number of hooks provided by WooCommerce, when you are clicking the Recalculate button.当您单击“重新计算”按钮时,WooCommerce 提供了许多挂钩。 I'm listing here those hooks and it depends on you to choose among them according to your requirement.我在这里列出了这些钩子,这取决于您根据您的要求在其中进行选择。

$order = WC_Order object $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM