【问题标题】:Add another button beside "Refund" button in WooCommerce admin orders在 WooCommerce 管理员订单中的“退款”按钮旁边添加另一个按钮
【发布时间】:2020-12-04 21:51:24
【问题描述】:

我想在 WooCommerce 的“编辑订单”页面中的退款按钮旁边添加一个用于其他操作的新按钮。

我知道它可能通过钩子实现,但我似乎找不到合适的钩子来执行它。

【问题讨论】:

标签: php ajax woocommerce backend hook-woocommerce


【解决方案1】:

使用以下 (您将在其中将“自定义”替换为您想要的操作 slug 和名称)

add_action( 'woocommerce_order_item_add_action_buttons', 'wc_order_item_add_action_buttons_callback', 10, 1 );
function wc_order_item_add_action_buttons_callback( $order ) {
    $label = esc_html__( 'Custom', 'woocommerce' );
    $slug  = 'custom';
    ?>
    <button type="button" class="button <?php echo $slug; ?>-items"><?php echo $label; ?></button>
    <?php
}

钩子位于includes/admin/meta-boxes/views/html-order-items.php (line 288)

然后你必须为这个按钮启用 Ajax,添加一些 jQuery 代码(发送者)和一些 PHP 代码(WordPress Admin Ajax 接收者),就像 WC_Ajax refund_line_items()...

【讨论】:

  • 工作就像一个魅力。谢谢!
猜你喜欢
  • 2013-09-16
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2011-07-05
  • 2022-01-12
  • 2013-07-31
  • 2016-09-05
  • 2021-06-14
相关资源
最近更新 更多