通过WooCommerce管理员批量订单操作获取自定义计算

易卜拉欣

我想使订单总数进入计算公式。

我有每个订单工资的司机。他们交付已付款和未付款的订单。因此,他们从客户那里收取未付的鳕鱼付款。最终,我计算出我必须向他们收取多少费用,并从金额中扣除他们的薪水。

公式为[('鳕鱼'订单总数)-(已交付订单数量)x 1.5]

这是一个例子

假设我们已经收到3份订单,并且司机收取了这些订单以便交付..因此,在一天结束时,司机不得不将现金带回..在这里,我想知道我必须从他那里收取多少钱,这要扣除他的工资

order A : total = 50 : payment method /cod
order B : total = 10 : payment method /cod
order C : total = 40 : payment method /credit card

    the calculation = [ 'cod' orders totals - (selected orders number ) x 1.5 ]

the calculation = [ ( 50 + 10 ) - (3 ) x 1.5 ] = 55.5

结果是(55.5)是我必须向驾驶员收取的金额

我不知道这是否必须在同一管理员订单页面或新页面上..我想象在WC的订单管理部分或单独的页面上,我可以从要创建的订单列表中检查订单例如,我选择了[批量操作1],然后从批量操作下拉框中进行计算,然后显示结果

LoicTheAztec

您可以使用以下代码,使您可以选择批量订单来计算问题中定义的从驱动程序收取的金额:

// Display the custom actions on admin Orders bulk action dropdown
add_filter( 'bulk_actions-edit-shop_order', 'orders_bulk_action_delivery_collect_calc' );
function orders_bulk_action_delivery_collect_calc( $bulk_actions ) {
    $bulk_actions['delivery-collect'] = __( "Calculate delivery collect", 'woocommerce' );

    return $bulk_actions;
}

// Process the bulk action from selected orders
add_filter( 'handle_bulk_actions-edit-shop_order', 'delivery_collect_calc_bulk_action_edit_shop_order', 10, 3 );
function delivery_collect_calc_bulk_action_edit_shop_order( $redirect_to, $action, $post_ids ) {

    if ( $action === 'delivery-collect' ) {
        $order_numbers    = []; // Initializing
        $cod_orders_total = 0; // Initializing
        $salary_per_order = 1.5;

        foreach ( $post_ids as $post_id ) {
            // Get Order status
            $order = wc_get_order( $post_id );

            if( $order->get_payment_method() === 'cod' ) {
                $cod_orders_total += (float) $order->get_total();
            }

            // Order status change to "completed" (To enable uncomment the line below)
            // $order->update_status("completed");

            $order_numbers[] = $order->get_order_number(); // Adding processed order numbers to an array
        }

        $orders_count      = count( $order_numbers );
        $amount_to_collect = $cod_orders_total - ( $orders_count * $salary_per_order );


        // Adding the right query vars to the returned URL
        $redirect_to = add_query_arg( array(
            'collect_action'     => $action,
            'processed_count'    => $orders_count,
            'proc_order_nums'      => implode( ',', $order_numbers ),
            'amount_to_collect'  => $amount_to_collect,
        ), $redirect_to );
    }
    return $redirect_to;
}

// Display the results notice from bulk action on orders
add_action( 'admin_notices', 'set_delivery_collect_bulk_action_admin_notice' );
function set_delivery_collect_bulk_action_admin_notice() {
    global $pagenow;

    if ( 'edit.php' === $pagenow && isset($_GET['post_type']) && 'shop_order' === $_GET['post_type']
    && isset($_GET['collect_action'])  && isset($_GET['processed_count'])
    && isset($_GET['proc_order_nums']) && isset($_GET['amount_to_collect']) ) {

        $count_ids = intval( $_GET['processed_count'] );
        $amount    = floatval( $_GET['amount_to_collect'] );
        $currency  = get_woocommerce_currency_symbol();

        printf( '<div class="notice notice-success fade is-dismissible"><p>' .
            _n( "On %s selected order, the calculated amount to collect is %sProcessed order Id is %s",
                "On the %s selected orders, the calculated amount to collect is %sProcessed orders Ids are %s.",
            $count_ids, "woocommerce" ) . '</p></div>',
            $count_ids,
            '<code>' . number_format_i18n($amount, 2) . '</code> (' . $currency . ').</p><p>',
            '<code>' . $_GET['proc_order_nums'] . '</code>'
        );
    }
}

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。

此自定义批量操作(在“订单”列表上的批量操作下拉菜单中):

在此处输入图片说明

可忽略的消息框中的计算结果:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Woocommerce管理员订单列表上处理多个自定义批量操作

在WooCommerce管理员订单列表中以批量操作添加自定义取消订单状态

在Woocommerce管理员订单编辑页面中以编程方式添加自定义订单注释

在Woocommerce管理员订单页面中保存订单项自定义字段

在Woocommerce管理员订单列表自定义列中显示结帐字段值

在Woocommerce管理员,订单和电子邮件中显示自定义付款字段

在WooCommerce管理员快速订单预览中自定义内容

在WooCommerce订单管理员中搜索自定义字段

如何在管理员上编辑或自定义WooCommerce添加订单按钮

如何为WooCommerce订单页面(管理员)添加自定义字段?

在Woocommerce管理员订单列表自定义列中显示用户名

Woocommerce在管理员订单详细信息上显示自定义字段数据

Woocommerce管理员编辑订单页面常规部分中的自定义可编辑字段

在Woocommerce管理员订单预览上显示自定义数据

在帐单地址后以WooCommerce管理员订单显示自定义元数据

在WooCommerce订单管理员列表上显示带有自定义用户元的自定义列

在WooCommerce管理员新订单自定义字段上加载用户自定义数据

在WooCommerce管理员订单页面上将产品自定义字段显示为订单项元

仅在WooCommerce管理员订单列表自定义列中显示特定订单状态的数据

在Woocommerce管理员订单列表“订单”现有列中添加自定义字段

Woocommerce 3.3管理员订单列表中的自定义订单状态背景按钮颜色

在Woocommerce中处理管理订单列表上的自定义批量操作

将产品自定义字段另存为WooCommerce管理员手动订单的自定义订单项元数据

WIX以管理员权限执行自定义操作

在Django中测试自定义管理员操作

基于自定义条件的Django管理员操作

自定义Flask管理员行操作

如何在WooCommerce管理员单笔订单中显示自定义结帐账单字段

Woocommerce管理员中的自定义可编辑字段将订单页面编辑到每个项目中