Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save themepaint/cfef5e5300d54aa4ab3a1b084c37361a to your computer and use it in GitHub Desktop.

Select an option

Save themepaint/cfef5e5300d54aa4ab3a1b084c37361a to your computer and use it in GitHub Desktop.

Revisions

  1. themepaint created this gist Apr 18, 2016.
    41 changes: 41 additions & 0 deletions Create Custome Field in Woocommerce Product Page
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php
    // Display Fields
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );

    function woo_add_custom_general_fields() {

    global $woocommerce, $post;

    echo '<div class="options_group">';

    woocommerce_wp_text_input(
    array(
    'id' => 'ali_express_link',
    'label' => __( 'AliExpress Link Here', 'woocommerce' ),
    'placeholder' => 'http://',
    'desc_tip' => 'true',
    'description' => __( 'Enter the AliExpress Link here.', 'woocommerce' )
    )
    );

    echo '</div>';

    }

    // Save Fields
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );

    function woo_add_custom_general_fields_save( $post_id ){

    // Text Field
    $woocommerceali_express_link = $_POST['ali_express_link'];
    if( !empty( $woocommerceali_express_link ) )
    update_post_meta( $post_id, 'ali_express_link', esc_attr( $woocommerceali_express_link ) );

    }


    // Display Custom Field Value
    $link = get_post_meta( get_the_ID(), 'ali_express_link', true );

    ?>