【问题标题】:Get a custom product meta to show up in order items post meta获取自定义产品元数据以显示在元数据后的订单项中
【发布时间】:2023-03-20 17:19:01
【问题描述】:

我有一个自定义产品元“zoho_id”https://ibb.co/F4M6gSh。我希望该元显示在元https://ibb.co/rsVTHxV 后的订单项中,以便在 Integromat 中使用它。我尝试了这段代码,因为我得到了订单元中的 ID 而不是发布项目,它的值是“数据”。如何让每个产品按顺序显示该元数据?

add_action( 'woocommerce_add_order_item_meta', 'pd_number_order_meta_data', 10, 3 );
function pd_number_order_meta_data( $item_id, $cart_item, $cart_item_key ) {
    $zohoid = get_post_meta( $cart_item[ 'product_id' ], 'zoho_id', true );
    if( ! empty($zohoid) )
        wc_update_order_item_meta( $item_id, 'zoho_id', $zohoid );
}

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我能够通过Pass custom product meta data to the order in Woocommerce 3 的以下代码实现它https://ibb.co/st6fcDH

    add_action('woocommerce_checkout_create_order_line_item', 'save_file_type_as_order_item_meta', 20, 4);
    function save_file_type_as_order_item_meta($item, $cart_item_key, $values, $order) {
        if ( $cost_centre = $values['data']->get_meta('zoho_id') ) {
            $item->update_meta_data( '_zoho_id', $cost_centre ); // Save as order item (visble on admin only)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 1970-01-01
      • 2019-05-10
      • 2020-12-29
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      相关资源
      最近更新 更多