Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active August 5, 2025 09:32
Show Gist options
  • Save igorbenic/1106ccf44c1061d80c2738bcbe09181d to your computer and use it in GitHub Desktop.
Save igorbenic/1106ccf44c1061d80c2738bcbe09181d to your computer and use it in GitHub Desktop.

Revisions

  1. igorbenic revised this gist May 6, 2017. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions save_product.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?php

    add_action( 'woocommerce_process_product_meta', 'save_custom_field' );

    function save_custom_field( $post_id ) {

    $custom_field_value = isset( $_POST['my_custom_input'] ) ? $_POST['my_custom_input'] : '';

    $product = wc_get_product( $post_id );
    $product->update_meta_data( 'my_custom_input', $custom_field_value );
    $product->save();

    }
  2. igorbenic revised this gist May 6, 2017. 3 changed files with 52 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions tab_action.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php

    add_action( 'woocommerce_product_write_panel_tabs', 'my_custom_tab_action' );

    /**
    * Adding a custom tab
    */
    function my_custom_tab_action() {
    ?>
    <li class="custom_tab">
    <a href="#the_custom_panel">
    <span><?php _e( 'My Custom Tab', 'textdomain' ); ?></span>
    </a>
    </li>
    <?php
    }
    16 changes: 16 additions & 0 deletions tab_filter.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php

    add_filter( 'woocommerce_product_data_tabs', 'my_custom_tab' );
    /**
    * Adding a custom tab
    */
    function my_custom_tab( $tabs ) {

    $tabs['custom_tab'] = array(
    'label' => __( 'My Custom Tab', 'textdomain' ),
    'target' => 'the_custom_panel',
    'class' => array(),
    );

    return $tabs;
    }
    20 changes: 20 additions & 0 deletions tab_panel.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?php

    add_action( 'woocommerce_product_data_panels', 'custom_tab_panel' );

    function custom_tab_panel() {
    ?>
    <div id="the_custom_panel" class="panel woocommerce_options_panel">
    <div class="options_group">
    <?php
    $field = array(
    'id' => 'my_custom_input',
    'label' => __( 'Custom Input', 'textdomain' ),
    );

    woocommerce_wp_text_input( $field );
    ?>
    </div>
    </div>
    <?php
    }
  3. igorbenic revised this gist May 6, 2017. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions general_tab.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <?php

    add_action( 'woocommerce_product_options_pricing', 'my_woo_custom_price_field' );
    /**
    * Add a Christmas Price field
    **/
    function my_woo_custom_price_field() {

    $field = array(
    'id' => 'christmas_price',
    'label' => __( 'Christmas Price', 'textdomain' ),
    'data_type' => 'price' //Let WooCommerce formats our field as price field
    );

    woocommerce_wp_text_input( $field );
    }

    add_action( 'woocommerce_product_options_general_product_data', 'my_woo_custom_fields' );
    /**
    * Add a select Field at the bottom
    */
    function my_woo_custom_fields() {
    $select_field = array(
    'id' => 'my_select',
    'label' => __( 'Custom Select', 'textdomain' ),
    'options' => array(
    'value1' => __( 'Text 1', 'textdomain' ),
    'value2' => __( 'Text 2', 'textdomain' )
    )
    );
    woocommerce_wp_select( $select_field );
    }
  4. igorbenic created this gist May 6, 2017.
    17 changes: 17 additions & 0 deletions checkbox_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php

    $args = array(
    'label' => '', // Text in Label
    'class' => '',
    'style' => '',
    'wrapper_class' => '',
    'value' => '', // if empty, retrieved from post meta where id is the meta_key
    'id' => '', // required
    'name' => '', //name will set from id if empty
    'cbvalue' => '',
    'desc_tip' => '',
    'custom_attributes' => '', // array of attributes
    'description' => ''
    );

    woocommerce_wp_checkbox( $args );
    8 changes: 8 additions & 0 deletions hidden_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <?php
    $args = array(
    'value' => '',
    'class' => '',
    'id' => ''
    );

    woocommerce_wp_hidden_input( $args );
    16 changes: 16 additions & 0 deletions radio_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php

    $args = array(
    'label' => '', // Text in Label
    'class' => '',
    'style' => '',
    'wrapper_class' => '',
    'value' => '', // if empty, retrieved from post meta where id is the meta_key
    'id' => '', // required
    'name' => '', //name will set from id if empty
    'options' => '', // Options for radio inputs, array
    'desc_tip' => '',
    'description' => ''
    );

    woocommerce_wp_radio( $args );
    18 changes: 18 additions & 0 deletions select_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php


    $args = array(
    'label' => '', // Text in Label
    'class' => '',
    'style' => '',
    'wrapper_class' => '',
    'value' => '', // if empty, retrieved from post meta where id is the meta_key
    'id' => '', // required
    'name' => '', //name will set from id if empty
    'options' => '', // Options for select, array
    'desc_tip' => '',
    'custom_attributes' => '', // array of attributes
    'description' => ''
    );

    woocommerce_wp_select( $args );
    19 changes: 19 additions & 0 deletions text_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php

    $args = array(
    'label' => '', // Text in Label
    'placeholder' => '',
    'class' => '',
    'style' => '',
    'wrapper_class' => '',
    'value' => '', // if empty, retrieved from post meta where id is the meta_key
    'id' => '', // required
    'name' => '', //name will set from id if empty
    'type' => '',
    'desc_tip' => '',
    'data_type' => '',
    'custom_attributes' => '', // array of attributes
    'description' => ''
    );

    woocommerce_wp_text_input( $args );
    19 changes: 19 additions & 0 deletions textarea_input.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php

    $args = array(
    'label' => '', // Text in Label
    'placeholder' => '',
    'class' => '',
    'style' => '',
    'wrapper_class' => '',
    'value' => '', // if empty, retrieved from post meta where id is the meta_key
    'id' => '', // required
    'name' => '', //name will set from id if empty
    'rows' => '',
    'cols' => '',
    'desc_tip' => '',
    'custom_attributes' => '', // array of attributes
    'description' => ''
    );

    woocommerce_wp_textarea_input( $args );