How to add custom meta data to the Order Items in woocommerce

时间:2017-12-18 08:34:02

标签: php wordpress

I am using this hook and adding custom meta data but it's not working. Can you please tell me how can i add custom meta data to the Order Items in woocommerce.

public boolean isFilePresent(Context context, String fileName) {
    File dirFiles = context.getFilesDir();

    File[] filesArray = dirFiles.listFiles();

    for (File file : filesArray) {
        if (file.getName().equals(fileName)) {
            return true;
        }
    }

    return false;
}

1 个答案:

答案 0 :(得分:1)

您需要使用 woocommerce_add_order_item_meta 挂钩,以便您的代码看起来像这样。

 add_action('woocommerce_add_order_item_meta','all_add_values_to_order_item_meta',10,3); // add extra order metas

function all_add_values_to_order_item_meta($item_id,$values) { if(!empty($values['tbb_right_sphere'])) { $tbb_right_sphere=$values['tbb_right_sphere']; wc_add_order_item_meta($item_id,'od_right_sphere',$tbb_right_sphere); } }