gpt4 book ai didi

mysql - 如何保存wordpress产品页面的设置?

转载 作者:行者123 更新时间:2023-11-29 07:20:18 25 4
gpt4 key购买 nike

enter image description here

我尝试了以下代码:

      if(isset($_POST['save']))
{
global $wpdb,$product;
$id = $product->id;

$custommsg = sanitize_text_field( $_POST['customstock-msg'] );
$customprocessingtime = sanitize_text_field( $_POST['customstock-Processing-time'] );
$customstockquantity = sanitize_text_field( $_POST['customstock-quantity'] );
$customstockcatlogpage = sanitize_text_field( $_POST['customstock-catlogpage'] );
$customstockinstockdate = sanitize_text_field( $_POST['customstock-instockdate'] );
$customstockinstockdate = date("Y-m-d", strtotime($customstockinstockdate) );

$wpdb->insert('wp_woocommerce_specific_product_settings', array(
'custom_msg' => $custommsg,
'order_processing_time' => $customprocessingtime,
'exp_instock_date' => $customstockinstockdate,
'show_stockstatus_quantity' => $customstockquantity,
'showon_catlog' => $customstockcatlogpage,
'specific_product_id' => $id
));
}

我是WordPress的初学者,任何人都可以提供解决方案。

最佳答案

您只需使用 woocommerce 的操作 Hook woocommerce_process_product_meta

以下是应放入您的functions.php 文件中的代码。您可能需要根据需要重命名自定义元字段。 (在 update_post_meta 语句中)。

add_action( 'woocommerce_process_product_meta', 'wp_woo_save_product_custom_meta' );
function wp_woo_save_product_custom_meta( $post_id ){
$custommsg = sanitize_text_field( $_POST['customstock-msg'] );
if( !empty( $custommsg ) ){
update_post_meta( $post_id, 'customstock_msg', $custommsg ) );
}
$customprocessingtime = sanitize_text_field( $_POST['customstock-Processing-time'] );
if( !empty( $customprocessingtime ) ){
update_post_meta( $post_id, 'customstock_Processing_time', $customprocessingtime ) );
}
$customstockquantity = sanitize_text_field( $_POST['customstock-quantity'] );
if( !empty( $customstockquantity ) ){
update_post_meta( $post_id, 'customstock_quantity', $customstockquantity ) );
}
$customstockcatlogpage = sanitize_text_field( $_POST['customstock-catlogpage'] );
if( !empty( $customstockcatlogpage ) ){
update_post_meta( $post_id, 'customstock_catlogpage', $customstockcatlogpage ) );
}
$customstockinstockdate = sanitize_text_field( $_POST['customstock-instockdate'] );
$customstockinstockdate = date("Y-m-d", strtotime($customstockinstockdate) );
if( !empty( $customstockinstockdate ) ){
update_post_meta( $post_id, 'customstock_instockdate', $customstockinstockdate ) );
}
}

关于mysql - 如何保存wordpress产品页面的设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36442642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com