Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. $attribute_keys = array_keys( $attributes );
  2.  
  3. function print_attribute_radio( $checked_value, $value, $label, $name ) {
  4.  
  5. $checked = sanitize_title( $checked_value ) === $checked_value ? checked( $checked_value, sanitize_title( $value ), false ) : checked( $checked_value, $value, false );
  6.  
  7. $input_name = 'attribute_' . esc_attr( $name ) ;
  8. $esc_value = esc_attr( $value );
  9. $id = esc_attr( $name . '_v_' . $value );
  10. $filtered_label = apply_filters( 'woocommerce_variation_option_name', $label );
  11. printf( '<div><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label );
  12. }
  13.  
  14. <table class="variations" cellspacing="0">
  15. <tbody>
  16. <?php foreach ( $attributes as $attribute_name => $options ) : ?>
  17. <tr>
  18. <td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
  19. <td class="value">
  20. <?php
  21. $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) : $product->get_variation_default_attribute( $attribute_name );
  22. wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
  23. echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
  24. ?>
  25. </td>
  26. </tr>
  27. <?php endforeach;?>
  28. </tbody>
  29. </table>
  30.  
  31. <?php foreach ( $attributes as $name => $options ) : ?>
  32. <table class="variations" cellspacing="0">
  33. <tbody>
  34. <tr>
  35. <?php
  36. $sanitized_name = sanitize_title( $name );
  37. if ( isset( $_REQUEST[ 'attribute_' . $sanitized_name ] ) ) {
  38. $checked_value = $_REQUEST[ 'attribute_' . $sanitized_name ];
  39. } elseif ( isset( $selected_attributes[ $sanitized_name ] ) ) {
  40. $checked_value = $selected_attributes[ $sanitized_name ];
  41. } else {
  42. $checked_value = '';
  43. }
  44. ?>
  45. <td class="value">
  46. <?php
  47. if ( ! empty( $options ) ) {
  48. if ( taxonomy_exists( $name ) ) {
  49. // Get terms if this is a taxonomy - ordered. We need the names too.
  50. $terms = wc_get_product_terms( $product->id, $name, array( 'fields' => 'all' ) );
  51.  
  52. foreach ( $terms as $term ) {
  53. if ( ! in_array( $term->slug, $options ) ) {
  54. continue;
  55. }
  56. print_attribute_radio( $checked_value, $term->slug, $term->name, $sanitized_name );
  57. }
  58. } else {
  59. foreach ( $options as $option ) {
  60. print_attribute_radio( $checked_value, $option, $option, $sanitized_name );
  61. }
  62. }
  63. }
  64.  
  65. echo end( $attribute_keys ) === $name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
  66. ?>
  67. </td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement