我正在尝试在创建订单时将自定义文本区域输入写入自定义 WordPress 表中。不幸的是,自定义文本区域输入未保存在我的自定义表中。只有一个“;”存储在我的自定义表的表列“cardcontent”中。我尝试使用 $_POST 访问我的自定义文本区域输入。我认为这是我的错误。
这是我当前在functions.php中的代码:
//triggers before checkout form is submited but order will be created.
add_action( 'woocommerce_checkout_update_order_meta', 'cpm_woocommerce_checkout_update', 10, 2 );
function cpm_woocommerce_checkout_update($order_id, $data) {
//trying to get my textarea input values with $_POST
$cardHeading = $_POST['heading'];
$cardBody = $_POST['bodytext'];
$order = wc_get_order( $order_id );
if (is_user_logged_in()) { //check if user is logged in.
global $current_user;
global $wpdb;
// get current user info
get_currentuserinfo();
$card = $cardHeading . ";" . $cardBody;
$timestamp = time();
$id = $current_user->ID;
// "$wpdb->prefix" will prepend your table prefix
$table_name = $wpdb->prefix."cards";
$data = array(
'userid' => $id,
'orderid' => $order_id,
'cardcontent' => $card,
'timestamp' => $timestamp,
);
$wpdb->insert( $table_name, $data );
}
}```
Do i have to attach them to the order first and then apply them to the order in the action?
Thanks in advance
JD
确保表单字段的名称(标题和正文)与您尝试在结帐页面上访问的 $_POST 值匹配。