简体   繁体   English

如何在woocommerce管理订单详细信息页面上添加操作按钮

[英]How to add action button on woocommerce admin order detail page

In Woocommerce, I have added button with meta boxes but on click of that button at admin order detail page showing order updated and next function is not getting execute. 在Woocommerce中,我添加了带元框的按钮,但是在管理订单详细信息页面上单击该按钮,显示订单已更新,下一个功能未执行。

This is my code: 这是我的代码:

add_action( 'add_meta_boxes', 'add_meta_boxesws' );
function add_meta_boxesws()
{
    add_meta_box( 
        'add_meta_boxes', 
        __( 'Custom' ), 
        'sun'
    );
}

function sun(){
    echo '<input type="hidden" value="abc" name="abc"/>';
    echo '<p><button id="mybutton" type="submit">Return Shipment</button></p>';
}

if ( !empty( $_POST['abc'] ) )  {
    function call_this(){
        echo "hello";    
    }
    add_action('dbx_post_sidebar','call_this');
}

Any Help will be appreciated. 任何帮助将不胜感激。

Is better to use the GET method and display the result in your meta-box content under the button itself. 最好使用GET方法并在按钮本身下的​​元框内容中显示结果。 So you will replace you <button> , by a <a href=""> html tag… 因此,您将通过<a href=""> html标记替换<button> ...

Your revisited code: 您重新访问的代码:

// Add a custom metabox only for shop_order post type (order edit pages)
add_action( 'add_meta_boxes', 'add_meta_boxesws' );
function add_meta_boxesws()
{
    add_meta_box( 'custom_order_meta_box', __( 'My Title' ),
        'custom_metabox_content', 'shop_order', 'normal', 'default');
}

function custom_metabox_content(){
    $post_id = isset($_GET['post']) ? $_GET['post'] : false;
    if(! $post_id ) return; // Exit

    $value="abc";
    ?>
        <p><a href="?post=<?php echo $post_id; ?>&action=edit&abc=<?php echo $value; ?>" class="button"><?php _e('Return Shipment'); ?></a></p>
    <?php
    // The displayed value using GET method
    if ( isset( $_GET['abc'] ) && ! empty( $_GET['abc'] ) ) {
        echo '<p>Value: '.$_GET['abc'].'</p>';
    }
}

Code goes in function.php file of your active child theme (or active theme). 代码位于活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。

在此输入图像描述

Once submitted: 提交后:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 管理订单列表中添加自定义操作按钮 - Add a custom action button in WooCommerce admin order list Woocommerce / Wordpress - 在管理面板上添加按钮到订单/产品页面 - Woocommerce / Wordpress - Add button to Order / Product Page on Admin Panel WooCommerce - 如何在管理订单页面中向产品列表添加列 - WooCommerce - How to add column to product list in admin order page Woocommerce的管理订单详情页如何显示全价(含税)? - How to display full price (including tax) in Admin Order Detail Page in Woocommerce? WooCommerce 为重新计算按钮添加订单管理挂钩 - WooCommerce add order admin hook for recalculate button WooCommerce:将自定义 Metabox 添加到管理订单页面 - WooCommerce : Add custom Metabox to admin order page "WooCommerce 管理订单列表中用于自定义订单状态的操作按钮问题" - Issue with action button in WooCommerce admin order list for custom order status 为Woocommerce管理员订单添加自定义订单状态的特定操作按钮图标 - Add specific action button icon for custom order status to Woocommerce admin orders 将img添加到Woocommerce的管理订单列表中的自定义操作按钮 - Add img to custom action buttons in admin order list for Woocommerce 在 woocommerce 管理订单页面中的自定义按钮点击上运行一个功能 - Run a function on custom button click in woocommerce admin order page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM