首页 > 解决方案 > 将自定义 WooCommerce 结帐字段导出到 ShipStation 自定义字段 2

问题描述

我正在尝试将结帐中的自定义字段导出到 ShipStation 中的自定义字段 2 中,但数据没有被拉入自定义字段 2。我可能在代码中使用了错误的元数据吗?

我已经从船站站点复制了我应该添加到我的functions.php中的片段

// Add this code to your theme functions.php file or a custom plugin
add_filter( 'woocommerce_shipstation_export_custom_field_2', 'shipstation_custom_field_2' );

function shipstation_custom_field_2() {
    return '_meta_key'; // Replace this with the key of your custom field
}

// This is for custom field 3
add_filter( 'woocommerce_shipstation_export_custom_field_3', 'shipstation_custom_field_3' );

function shipstation_custom_field_3() {
    return '_meta_key_2'; // Replace this with the key of your custom field
}

对于我正在开发的网站,我在结帐时有一个自定义结帐字段,用于显示缺货选项。我已将“_meta_key_2”替换为客户缺货选项“outofstockoption”的元数据

function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ( ! empty( $_POST['outofstockoption'] ) ) {
        update_post_meta( $order_id, 'Out of Stock Option', sanitize_text_field( $_POST['outofstockoption'] ) );
    }
}

// Add this code to your theme functions.php file or a custom plugin
add_filter( 'woocommerce_shipstation_export_custom_field_2', 'shipstation_custom_field_2' );

function shipstation_custom_field_2() {
    return 'outofstockoption'; // Replace this with the key of your custom field
}

我希望有人可以指导我如何让 ShipStation 拉出“缺货选项”并将其放入 ShipStation 自定义字段中。提前致谢。

标签: phpwordpresswoocommerce

解决方案


在你的行中 -

update_post_meta( $order_id, 'Out of Stock Option', sanitize_text_field( $_POST['outofstockoption'] ) );

您将 _meta_key 分配为“缺货选项”。要将其用作元键并将其发送到 ShipStation,请将您的函数更新为 -

function shipstation_custom_field_2() {
    return 'Out of Stock Option'; 
}

推荐阅读