0

I'd like to have a simple custom meta for order items that says if the item has been fulfilled or not. enter image description here

I have this in my functions.php:

add_action( 'woocommerce_admin_order_item_values', 'pd_admin_order_item_values', 10, 3 );
function pd_admin_order_item_values( $product, $item, $item_id ) {
    //Get what you need from $product, $item or $item_id
    echo '<td class="fulfilled">';
    $fulfilled = wc_get_order_item_meta($item_id, '_fulfilled', true);
    if ($fulfilled) {
        echo '<p><strong>Fulfilled:</strong> <span style="color:#00FF00;">Yes</span></p>';
    } else {
        echo '<p><strong>Fulfilled:</strong> <span style="color:#FF0000;">No</span></p>';
    }
    echo'</td>';
}

Is there an easy way to update the meta value just by clicking the Yes/No?

Like, click the green Yes and it updates to a red No and viceversa.

Will I have to create a custom WC API endpoint?

  • You're on the right track. You don't need to create a WC API endpoint, just use admin_ajax.php and create an action. You'll then also need to create a jQuery Click bind to handle the ajax request – Moe Sep 4 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.