【问题标题】:Export Custom WooCommerce Checkout Field to ShipStation Custom Field 2将自定义 WooCommerce 结帐字段导出到 ShipStation 自定义字段 2
【发布时间】:2019-04-09 09:09:44
【问题描述】:

我正在尝试将结帐中的自定义字段导出到 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 自定义字段。提前致谢。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    在你的行中 -

    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'; 
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2017-03-21
      • 2013-07-07
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 2022-01-03
      相关资源
      最近更新 更多