Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create new fields for variations
- *
- */
- function variable_fields( $loop, $variation_data ) {
- ?>
- <tr>
- <td>
- <?php
- // Text Field
- woocommerce_wp_text_input(
- array(
- 'id' => 'color_hex['.$loop.']',
- 'label' => __( 'Swatch Color', 'woocommerce' ),
- 'placeholder' => '#ffffff',
- 'desc_tip' => 'true',
- 'description' => __( 'Enter hex value of color to display when option is selected.', 'woocommerce' ),
- 'value' => $variation_data['color_hex'][0]
- )
- );
- ?>
- </td>
- </tr>
- <?php
- }
- /**
- * Create new fields for new variations
- *
- */
- function variable_fields_js() {
- ?>
- <tr>
- <td>
- <?php
- // Text Field
- woocommerce_wp_text_input(
- array(
- 'id' => 'color_hex[ + loop + ]',
- 'label' => __( 'Swatch Color', 'woocommerce' ),
- 'placeholder' => '#ffffff',
- 'desc_tip' => 'true',
- 'description' => __( 'Enter hex value of color to display when option is selected.', 'woocommerce' ),
- 'value' => $variation_data['color_hex'][0]
- )
- );
- ?>
- </td>
- </tr>
- <?php
- }
- /**
- * Save new fields for variations
- *
- */
- function save_variable_fields( $post_id ) {
- if (isset( $_POST['variable_sku'] ) ) :
- $variable_sku = $_POST['variable_sku'];
- $variable_post_id = $_POST['variable_post_id'];
- // Text Field
- $color_hex = $_POST['color_hex'];
- for ( $i = 0; $i < sizeof( $variable_sku ); $i++ ) :
- $variation_id = (int) $variable_post_id[$i];
- if ( isset( $color_hex[$i] ) ) {
- update_post_meta( $variation_id, 'color_hex', stripslashes( $color_hex[$i] ) );
- }
- endfor;
- endif;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement