第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

自定義價(jià)格字段未保存在 WooCommerce 中的管理產(chǎn)品中

自定義價(jià)格字段未保存在 WooCommerce 中的管理產(chǎn)品中

PHP
qq_笑_17 2023-06-18 16:22:38
我向 WooCommerce 添加了一個(gè)自定義價(jià)格字段。該字段按預(yù)期出現(xiàn),但它不保存輸入的值。我functions.php文件中的代碼是:/* Add custom price field to general page */function wc_cost_product_field() {    woocommerce_wp_text_input( array( 'id' => 'wholesaler_price', 'class' => 'wc_input_price short', 'label' => __( 'Wholesaler price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' ) );}add_action( 'woocommerce_product_options_pricing', 'wc_cost_product_field' );function pcc_save_custom_price( $post_id ) {    // Grab the custom price from $_POST    $custom_price = isset( $_POST[ 'wholesale_price' ] ) ? sanitize_text_field( $_POST[ 'wholesale_price' ] ) : '';    // grab the product    $product = wc_get_product( $post_id );    // Save the custom price using WooCommerce built-in functions    $product->update_meta_data( 'wholesale_price', $custom_price );    $product->save();}add_action( 'woocommerce_process_product_meta', 'pcc_save_custom_price' );
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

你有一些小錯(cuò)誤,這應(yīng)該足夠了


另請(qǐng)注意使用woocommerce_admin_process_product_objectto save 而不是過(guò)時(shí)的woocommerce_process_product_meta鉤子


/* Add custom price field to general page */

function action_woocommerce_product_options_pricing() { 

    woocommerce_wp_text_input( array(

        'id' => 'wholesaler_price', 

        'class' => 'wc_input_price short', 

        'label' => __( 'Wholesaler price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',

    ) );

}


add_action( 'woocommerce_product_options_pricing', 'action_woocommerce_product_options_pricing', 10, 0 );


// Save Fields

function action_woocommerce_admin_process_product_object( $product ) {

    if( isset($_POST['wholesaler_price']) ) {

        $product->update_meta_data( 'wholesaler_price', sanitize_text_field( $_POST[ 'wholesaler_price'] ) );

    }

}

add_action( 'woocommerce_admin_process_product_object', 'action_woocommerce_admin_process_product_object', 10, 1 ); 



查看完整回答
反對(duì) 回復(fù) 2023-06-18
  • 1 回答
  • 0 關(guān)注
  • 159 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)