WooCommerce Update Item Meta Table

This is all pretty new to me, but what I’ve done is created a form to update some of the individual woocommerce_order_itemmeta. I’m not receiving any errors, but my table data isn’t updating when I submit the form so I’m not sure where I went wrong.

When the form is submitted it should update the corresponding meta data in the “woocommerce_order_itemmeta” table.

Read More

HTML

<form method="post" id="project-info" action="/wp-content/themes/Avada/update_item_meta.php">
    <table class="project-info-form">
        <tr>
            <td><label>Item ID: </label>
                <select name="project-item-id">
                    <option value=""></option>
                    <option value="35">35</option>
                    <option value="36">36</option>
                </select>
            </td>
            <td>
                <label>Project ID: </label>
                <input type="number" name="pid">
            </td>
            <td>
                <label>Start Count: </label>
                <input type="number" name="scount">
            </td>
            <td>
                <label>End Count: </label>
                <input type="number" name="ecount">
            </td>
       </tr>
       <tr>
            <td align="right" colspan="4">
                <input type="submit" value="Update Item" class="update-item-button">
            </td>
       </tr>
    </table>
</form>

Form action update_item_meta.php

<?php

    global $woocommerce, $wpdb;

    $item_id = $_POST['project-item-id'];

    $pid = wc_update_order_item_meta($item_id, 'pid', $_POST['pid']);
    $scount = wc_update_order_item_meta($item_id, 'start_count', $_POST['scount']);
    $ecount = wc_update_order_item_meta($item_id, 'end_count', $_POST['ecount']);

    if( isset( $_POST['project-item-id'] )){
        return array($pid,$scount,$ecount);
}

?>

Related posts