Last active
April 17, 2020 08:17
-
-
Save imran-khan1/adf7d1f9b0ad0d0c9fd791197b853d23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Admin side Variable product fields | |
add_action( 'woocommerce_product_after_variable_attributes', 'ci_variation_settings_fields', 10, 3 ); | |
// Create new fields for variations | |
function ci_variation_settings_fields( $loop, $variation_data, $variation ) { | |
// Text Field | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'ci_text_field[' . $variation->ID . ']', | |
'label' => __( 'My Text Field', 'woocommerce' ), | |
'placeholder' => 'Enter text field value', | |
'desc_tip' => 'true', | |
'description' => __( 'Enter the text field value here.', 'woocommerce' ), | |
'value' => get_post_meta( $variation->ID, 'ci_text_field', true ) | |
) | |
); | |
// Number Field | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'ci_number_field[' . $variation->ID . ']', | |
'label' => __( 'My Number Field', 'woocommerce' ), | |
'desc_tip' => 'true', | |
'description' => __( 'Enter the custom number here.', 'woocommerce' ), | |
'value' => get_post_meta( $variation->ID, 'ci_number_field', true ), | |
'custom_attributes' => array( | |
'step' => 'any', | |
'min' => '0' | |
) | |
) | |
); | |
// Textarea | |
woocommerce_wp_textarea_input( | |
array( | |
'id' => 'ci_textarea[' . $variation->ID . ']', | |
'label' => __( 'My Textarea', 'woocommerce' ), | |
'placeholder' => '', | |
'description' => __( 'Enter the custom value here.', 'woocommerce' ), | |
'value' => get_post_meta( $variation->ID, 'ci_textarea', true ), | |
) | |
); | |
// Select | |
woocommerce_wp_select( | |
array( | |
'id' => 'ci_select[' . $variation->ID . ']', | |
'label' => __( 'My Select Field', 'woocommerce' ), | |
'description' => __( 'Choose a value.', 'woocommerce' ), | |
'value' => get_post_meta( $variation->ID, 'ci_select', true ), | |
'options' => array( | |
'one' => __( 'CI Option 1', 'woocommerce' ), | |
'two' => __( 'CI Option 2', 'woocommerce' ), | |
'three' => __( 'CI Option 3', 'woocommerce' ) | |
) | |
) | |
); | |
// Checkbox | |
woocommerce_wp_checkbox( | |
array( | |
'id' => 'ci_checkbox[' . $variation->ID . ']', | |
'label' => __('My Checkbox Field', 'woocommerce' ), | |
'description' => __( 'Check me!', 'woocommerce' ), | |
'value' => get_post_meta( $variation->ID, 'ci_checkbox', true ), | |
) | |
); | |
// Hidden field | |
woocommerce_wp_hidden_input( | |
array( | |
'id' => 'ci_hidden_field[' . $variation->ID . ']', | |
'value' => 'hidden_value' | |
) | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment