在使用插件管理自定义订单字段的WooCommerce中,我在WooCommerce管理订单列表中添加了一个自定义字段“回扣状态”,其中有3个值“无回扣”、“未付款”和“已付款”。
我还将其显示在查看订单屏幕上,如下面的屏幕截图所示:
现在我想批量更新所选订单的折扣状态,就像wooCommerce允许批量更改订单状态一样。
基于“在Woocommerce中处理管理员订单列表上的自定义批量操作”回答线程,我成功地在批量编辑下拉列表中添加了3种折扣状态(如第一个屏幕截图所示):
add_filter( 'bulk_actions-edit-shop_order', 'decrease_meals_orders_bulk_actions' );
function decrease_meals_orders_bulk_actions( $bulk_actions ) {
$bulk_actions['mr_norebates'] = 'Mark Transactions as No Rebates';
$bulk_actions['mr_unpaid'] = 'Mark Transactions as Unpaid';
$bulk_actions['mr_paid'] = 'Mark Transactions as Paid';
return $bulk_actions;
}
但是,当我尝试批量更新所选订单的回扣状态时,不会应用任何更改。
回扣状态的元键是\u wc\u acof\u 2
我也陷入困境,不知道如何解决这个问题。
感谢您的帮助。
事实上,我让它在你的代码的帮助下工作,但是它太长了,我很感激如果你能让它变得简单...
add_filter( 'bulk_actions-edit-shop_order', 'decrease_meals_orders_bulk_actions' );
function decrease_meals_orders_bulk_actions( $bulk_actions ) {
$bulk_actions['mr_norebates'] = 'Mark Transactions as No Rebates';
$bulk_actions['mr_unpaid'] = 'Mark Transactions as Unpaid';
$bulk_actions['mr_paid'] = 'Mark Transactions as Paid';
return $bulk_actions;
}
// Process the bulk action from selected orders
add_filter( 'handle_bulk_actions-edit-shop_order', 'decrease_meals_bulk_action_edit_shop_order', 10, 3 );
function decrease_meals_bulk_action_edit_shop_order( $redirect_to, $action, $post_ids ) {
if ( $action === 'mr_norebates' ){
$processed_ids = array(); // Initializing
foreach ( $post_ids as $post_id ) {
// Get number of meals
$nb_meal = get_post_meta( $post_id, '_wc_acof_2', true );
// Save the decreased number of meals ($meals - 1)
update_post_meta( $post_id, '_wc_acof_2', $nb_meal = 'norebates' );
$processed_ids[] = $post_id; // Adding processed order IDs to an array
}
// Adding the right query vars to the returned URL
$redirect_to = add_query_arg( array(
'mr_norebates' => 'No Rebates',
'processed_count' => count( $processed_ids ),
'processed_ids' => implode( ',', $processed_ids ),
), $redirect_to );
}
elseif ( $action === 'mr_unpaid' ){
$processed_ids = array(); // Initializing
foreach ( $post_ids as $post_id ) {
// Get number of meals
$nb_meal = get_post_meta( $post_id, '_wc_acof_2', true );
// Save the decreased number of meals ($meals - 1)
update_post_meta( $post_id, '_wc_acof_2', $nb_meal = 'unpaid' );
$processed_ids[] = $post_id; // Adding processed order IDs to an array
}
// Adding the right query vars to the returned URL
$redirect_to = add_query_arg( array(
'mr_unpaid' => 'Unpaid',
'processed_count' => count( $processed_ids ),
'processed_ids' => implode( ',', $processed_ids ),
), $redirect_to );
}
elseif ( $action === 'mr_paid' ){
$processed_ids = array(); // Initializing
foreach ( $post_ids as $post_id ) {
// Get number of meals
$nb_meal = get_post_meta( $post_id, '_wc_acof_2', true );
// Save the decreased number of meals ($meals - 1)
update_post_meta( $post_id, '_wc_acof_2', $nb_meal = 'paid' );
$processed_ids[] = $post_id; // Adding processed order IDs to an array
}
// Adding the right query vars to the returned URL
$redirect_to = add_query_arg( array(
'mr_paid' => 'Paid',
'processed_count' => count( $processed_ids ),
'processed_ids' => implode( ',', $processed_ids ),
), $redirect_to );
}
return $redirect_to;
}
// Display the results notice from bulk action on orders
add_action( 'admin_notices', 'decrease_meals_bulk_action_admin_notice' );
function decrease_meals_bulk_action_admin_notice() {
if ( empty( $_REQUEST['mr_norebates'] ) ) return; // Exit
$count = intval( $_REQUEST['processed_count'] );
printf( '<div id="message" class="updated fade"><p>' .
_n( 'Selected %s transaction updated.',
'Selected %s transactions updated.',
$count,
'mr_norebates'
) . '</p></div>', $count );
这是一种完整、紧凑和优化的方法,可用于3项操作中的每一项,批量更新您的自定义“返利状态”,显示摘要通知:
// Your settings in a function
function custom_admin_orders_bulk_actions( $labels = false ){
$domain = 'woocommerce';
return array(
'mr_norebates' => $labels ? __('No Rebates', $domain) : 'norebates',
'mr_unpaid' => $labels ? __('Unpaid', $domain) : 'unpaid',
'mr_paid' => $labels ? __('Paid', $domain) : 'paid',
);
}
// Display the custom actions on admin Orders bulk action dropdown
add_filter( 'bulk_actions-edit-shop_order', 'set_transactions_orders_bulk_actions' );
function set_transactions_orders_bulk_actions( $bulk_actions ) {
foreach( custom_admin_orders_bulk_actions(true) as $key => $label ) {
$bulk_actions[$key] = sprintf( __('Mark Transactions as %s', 'woocommerce'), $label );
}
return $bulk_actions;
}
// Process the bulk action from selected orders
add_filter( 'handle_bulk_actions-edit-shop_order', 'set_transactions_bulk_action_edit_shop_order', 10, 3 );
function set_transactions_bulk_action_edit_shop_order( $redirect_to, $action, $post_ids ) {
$actions = custom_admin_orders_bulk_actions();
if ( in_array( $action, array_keys($actions) ) ) {
$processed_ids = array(); // Initializing
foreach ( $post_ids as $post_id ) {
// Save the new value
update_post_meta( $post_id, '_wc_acof_2', $actions[$action] );
$processed_ids[] = $post_id; // Adding processed order IDs to an array
}
// Adding the right query vars to the returned URL
$redirect_to = add_query_arg( array(
'rebate_action' => $action,
'processed_count' => count( $processed_ids ),
'processed_ids' => implode( ',', $processed_ids ),
), $redirect_to );
}
return $redirect_to;
}
// Display the results notice from bulk action on orders
add_action( 'admin_notices', 'set_transactions_bulk_action_admin_notice' );
function set_transactions_bulk_action_admin_notice() {
global $pagenow;
if ( 'edit.php' === $pagenow && isset($_GET['post_type']) && 'shop_order' === $_GET['post_type']
&& isset($_GET['rebate_action']) && isset($_GET['processed_count']) && isset($_GET['processed_ids']) ) {
foreach( custom_admin_orders_bulk_actions(true) as $key => $label ) {
if ( $_GET['rebate_action'] === $key ) {
$count = intval( $_GET['processed_count'] );
printf( '<div class="notice notice-success fade is-dismissible"><p>' .
_n( '%s selected order updated to "%s" rebate status.',
'%s selected orders updated to "%s" rebate status.',
$count, 'woocommerce' )
. '</p></div>', $count, $label );
}
}
}
}
代码functions.php活动子主题(或活动主题)的文件中。测试和工作。
基于:在Woocommerce中处理管理订单列表上的自定义批量操作
我已按照此说明为我的WooCommerce订单添加自定义订单状态。 我找不到创建自定义操作按钮的方法,该按钮可将订单状态从管理订单列表页面更改为我的自定义状态,如下图所示: 我想为具有“处理”状态的订单显示此自定义操作按钮。 我在WooCommerce留档中找不到任何答案。 有没有钩子可以套用这些按钮? 如何将其添加到中? 非常感谢。
在新的woo orders屏幕上,旧的彩色状态图标现在消失了,取而代之的是一个带有彩色背景的大状态按钮。 处理为绿色,完成为蓝色,取消为灰色等。 我在woocommerce orders中有一个自定义订单状态,名为:in progress。自定义订单状态似乎也只给出一个默认的灰色背景。我想为我的自定义订单状态分配一个颜色背景。我曾试图找到一个代码片段,以便这样做,但一直没有运气。
使用以下代码,我可以在WooCommerce产品上获得一个自定义字段,但是如何在订单、结帐和管理订单(后端)上显示它呢? 这是我在每个产品上的自定义字段 这是我的管理订单(后端)详细信息。我尝试显示我在每个产品帖子中输入的正确元数据。 如何在管理订单中显示我在自定义字段中输入的值?我也希望有人能帮助我显示在订单和结帐页面的元。。。或者引导我走向正确的方向。我意识到,为了在管理订单中显示它,我必须确
但这给了我添加列中的“未定义变量”错误。 如果我只将放入函数中,它将“rechnung beilegen”输出到my_column_id_2中的每一行。像这样: 因此,问题是:如何根据中的选择将输出转换为?
订单管理位于WooCommerce - 订单下,当你的站点开始收到订单后,就能看到这个菜单。订单仅对管理员和商店经理/Shop Manager可见,每个订单有一个唯一的ID,这个ID就是WordPress post_id,是不连续的。本文简单介绍一下WooCommerce订单管理的方法。 订单状态的含义 待付款 / Pending Payment 成功下单但未支付订单,等待付款。如果支付网关的no
我想在页面中添加一个自定义按钮,管理员可以在其中手动创建新订单(管理员订单页面)。 管理员- 在我添加产品和点击编辑按钮后,我可以在添加元按钮附近显示自定义按钮吗?我找不到可以使用的钩子。 我已经添加了上面的代码。我得到了结果,但按钮显示后不久,我添加的产品。我只希望按钮显示时,我点击编辑按钮。 #更新 当我添加以下代码时,它起了作用。这条路对吗?由于设置了同一字段中的按钮