product-attributes.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Product attributes
  4. *
  5. * Used by list_attributes() in the products class.
  6. *
  7. * This template can be overridden by copying it to yourtheme/woocommerce/single-product/product-attributes.php.
  8. *
  9. * HOWEVER, on occasion WooCommerce will need to update template files and you
  10. * (the theme developer) will need to copy the new files to your theme to
  11. * maintain compatibility. We try to do this as little as possible, but it does
  12. * happen. When this occurs the version of the template file will be bumped and
  13. * the readme will list any important changes.
  14. *
  15. * @see https://docs.woocommerce.com/document/template-structure/
  16. * @author WooThemes
  17. * @package WooCommerce/Templates
  18. * @version 3.1.0
  19. */
  20. if ( ! defined( 'ABSPATH' ) ) {
  21. exit;
  22. }
  23. ?>
  24. <table class="shop_attributes">
  25. <?php if ( $display_dimensions && $product->has_weight() ) : ?>
  26. <tr>
  27. <th><?php _e( 'Weight', 'woocommerce' ) ?></th>
  28. <td class="product_weight"><?php echo esc_html( wc_format_weight( $product->get_weight() ) ); ?></td>
  29. </tr>
  30. <?php endif; ?>
  31. <?php if ( $display_dimensions && $product->has_dimensions() ) : ?>
  32. <tr>
  33. <th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
  34. <td class="product_dimensions"><?php echo esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ); ?></td>
  35. </tr>
  36. <?php endif; ?>
  37. <?php foreach ( $attributes as $attribute ) : ?>
  38. <tr>
  39. <th><?php echo wc_attribute_label( $attribute->get_name() ); ?></th>
  40. <td><?php
  41. $values = array();
  42. if ( $attribute->is_taxonomy() ) {
  43. $attribute_taxonomy = $attribute->get_taxonomy_object();
  44. $attribute_values = wc_get_product_terms( $product->get_id(), $attribute->get_name(), array( 'fields' => 'all' ) );
  45. foreach ( $attribute_values as $attribute_value ) {
  46. $value_name = esc_html( $attribute_value->name );
  47. if ( $attribute_taxonomy->attribute_public ) {
  48. $values[] = '<a href="' . esc_url( get_term_link( $attribute_value->term_id, $attribute->get_name() ) ) . '" rel="tag">' . $value_name . '</a>';
  49. } else {
  50. $values[] = $value_name;
  51. }
  52. }
  53. } else {
  54. $values = $attribute->get_options();
  55. foreach ( $values as &$value ) {
  56. $value = make_clickable( esc_html( $value ) );
  57. }
  58. }
  59. echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
  60. ?></td>
  61. </tr>
  62. <?php endforeach; ?>
  63. </table>