我在產品資料選項面板上建立了一個自訂選項卡,但是我不知道如何在其中編寫內容。我已經有一個使用鉤子列印庫存選項(複選框、文字等)的程式碼。 add_action('woocommerce_product_options_sku','add_leadlovers_custom_fields' );
我使用這段程式碼產生了這個選項卡。
function adicionar_guia_leadlovers($tabs) { $tabs['guia_leadlovers'] = array( 'label' => __( 'LeadLovers', 'text-domain' ), 'target' => 'leadlovers_product_data', 'class' => array( 'show_if_simple', 'show_if_variable' ), ); return $tabs; } add_filter( 'woocommerce_product_data_tabs', 'adicionar_guia_leadlovers' );
但是,我應該使用什麼鉤子來替代 'woocommerce_product_options_sku' 並在我的自訂選項卡上編寫選項呢?
P粉8051077172023-07-22 09:56:50
這是缺少的鉤子函數,用於顯示內容(和保存欄位值)以供您的附加產品設定標籤 "LeadLovers" 使用:
add_filter( 'woocommerce_product_data_tabs', 'add_leadlovers_guide_product_tab' ); function add_leadlovers_guide_product_tab($tabs) { $tabs['leadlovers_guide'] = array( 'label' => __( 'LeadLovers', 'text-domain' ), 'target' => 'leadlovers_product_data', 'class' => array( 'show_if_simple', 'show_if_variable' ), ); return $tabs; } // Display the content add_action( 'woocommerce_product_data_panels', 'display_readlovers_guide_product_data_tab_content' ); function display_readlovers_guide_product_data_tab_content() { global $product_object; echo '<div id="leadlovers_product_data" class="panel woocommerce_options_panel"> <div class="options_group">'; ## ---- Content Start ---- ## echo '<p>This is your LeadLovers content for the product "<strong>'.$product_object->get_name().'</strong>"…</p>'; woocommerce_wp_text_input( array( 'id' => '_leadlovers', 'value' => $product_object->get_meta('_leadlovers'), 'label' => __('LeadLovers field', 'woocommerce'), 'placeholder' => '', 'description' => __('LeadLovers description text.', 'woocommerce'), )); ## ---- Content End ---- ## echo '</div></div>'; } // Save field values add_action( 'woocommerce_admin_process_product_object', 'save_leadlovers_guide_fields_values' ); function save_leadlovers_guide_fields_values( $product ) { $leadlovers = isset( $_POST['_leadlovers'] ) ? sanitize_text_field($_POST['_leadlovers']) : ''; $product->update_meta_data( '_leadlovers', $leadlovers ); }
這樣就行了