• Resolved rhflorida

    (@rhflorida)


    Hi there. I’m loving the plugin so far, but am having some issues working my way through the possible configuration for syncing.

    I added the custom field “Vendor” to Post Type:Product and Post Type:Product Variation. I also created another custom field “Vendor” and added to Post Type:Order.

    I also have Admin Columns installed and am displaying the Vendor field which was added to Post Type:Order on the Order Grid page.

    The desired outcome is that when a customer purchases a product with an associated Vendor, that Vendor name shows up on the Order grid. Is that possible somehow?

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello!

    There’s no built-in functions available to achieve what you’re trying to do. Woocommerce is a very specific plugin which has it’s own logic and process. Based on what you described, here is a code that will update the order “Vendor” field based on the product “Vendor”:

    
    add_action('woocommerce_new_order_item', 'acf_woocommerce_update_order_field', 10, 3);
    function acf_woocommerce_update_order_field($item_id, $item, $order_id){
        
        // Get product from current order
        $product_id = $item->get_product_id();
    
        // Get vendor from product
        $vendor_value = get_field('vendor', $product_id);
        
        // Update vendor for the order
        update_field('vendor', $vendor_value, $order_id);
    
    }
    

    However, I would suggest you to take a look at official Woocommerce plugins here: https://woocommerce.com/product-category/woocommerce-extensions/ (This one may interest you: https://woocommerce.com/products/admin-custom-order-fields/).

    Those plugins will greatly help you to customize your Woocommerce experience, without having to add bunch of code in your theme.

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Sync fields between post types – Product and Order’ is closed to new replies.