Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save themepaint/cfef5e5300d54aa4ab3a1b084c37361a to your computer and use it in GitHub Desktop.
Save themepaint/cfef5e5300d54aa4ab3a1b084c37361a to your computer and use it in GitHub Desktop.
Create Custome Field in Woocommerce Product Page
<?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 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment