WooCommerce 挂钩添加自定义订单列

时间:2021-06-15 07:26:09

标签: wordpress woocommerce

我正在使用 WooCommerce hook,它在 WooCommerce->Orders 页面中添加了一个自定义列。

钩子被称为:manage_shop_order_posts_custom_column

现在,我添加了两个自定义列。其中之一包含一个从数据库中获取值并显示为选定的下拉列表。我想要做的是允许用户使用下拉表单更改状态,并且我还在那里放置了一个提交按钮。

但是,我面临一个非常奇怪的问题。也就是说,该表单仅针对第 1 个订单(第 1 行)和其他订单发布,提交按钮不发布任何数据,因此我无法在此按钮单击时运行更新查询。我还分享了下面的代码片段:

case 'my-column2':
    $sql    = "SELECT payment_status FROM custom_payments_data WHERE order_id = " . $post_id;
    $result = $dbConnection->query( $sql );
    
    if ( $result->num_rows > 0 ) {
        while ( $row = $result->fetch_assoc() ) {
            $status = $row["payment_status"];
        }
        ?>
        <!-- Building Payment Status form in WooCommerce Admin Orders -->
        <form action = "<?php echo plugin_dir_url( __FILE__ ). 'order_update.php';?>" method ="POST">
            <select style= "width: 100%;" id = "status" name = "status" class = "no-link">
                <option value = "Waiting Confirmation" <?php if($status == "Waiting Confirmation") echo 'selected = "selected"' ?>> Waiting Confirmation</option>
                <option value = "Pending Payment" <?php if($status == "Pending Payment") echo 'selected="selected"' ?>> Pending Payment</option>
                <option value = "Confirmed" <?php if($status == "Confirmed") echo 'selected="selected"' ?>> Confirmed</option>
            </select>
            <input type = "submit" class = "MyURLsubmit no-link"  name ="submit" id="MyURLsubmit" value = "Change Status">
        </form>
        <?php
        //} //End of while
    } // End of IF statement FORM
        break;
    }

0 个答案:

没有答案