In the individual product data options settings in WooCommerce admin, add content to custom tabs.
P粉477369269
P粉477369269 2023-07-21 15:47:05
0
1
454

I created a custom tab on the product data options panel, but I don't know how to write content in it. I already have a code that prints inventory options (checkboxes, text, etc.) using hooks. add_action('woocommerce_product_options_sku','add_leadlovers_custom_fields' );

I generated this tab using this code.

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' );

But what hook should I use to replace 'woocommerce_product_options_sku' and write options on my custom tab?

P粉477369269
P粉477369269

reply all(1)
P粉805107717

This is the missing hook function for displaying content (and saving field values) for use by your add-on product settings tab "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 );
}

That'll be fine

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template