php - 将自定义 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 自定义字段中。提前致谢。
解决方案
在你的行中 -
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';
}
推荐阅读
- sql - 自引用表上的合并约束错误
- testing - 如何在脚本模式下在 Katalon Studio 中编写测试步骤的描述?
- php - 如果满足条件,则更新数据库中的 ID 号
- windows - 我可以使用 windows.old 文件从 Windows 7 回到 Windows 10
- jsf - ui:param 无法在复合组件内的 actionListener 中进行评估
- image - 在 Windows 中,图像被裁剪为 5px 高。检查元素显示“固有尺寸”
- installation - 无法通过 Nix 安装 darcs
- php - 在 PHP 脚本中使用 POST 和 isset 时嵌套的 ajax 函数不产生任何结果
- javascript - JavaScript 从带“,”的字符串到 Int 的转换
- javascript - 如何使客户端 Socket 发出的值在全局范围内可用?