Advertisement
Evengar

Untitled

Jan 31st, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. add_action( 'woocommerce_after_shop_loop_item', 'add_attr_catalog', 3 );
  2.  
  3. function add_attr_catalog() {
  4.     global $product;
  5.     $attributes = $product->get_attributes();
  6.  
  7.     foreach ($attributes as $attribute) {
  8.          //print_r($attribute);
  9.          $attr_name =  substr($attribute['name'], 3);
  10.          $attr_value = $attribute['value'];
  11.          $attr_nice_name = get_attr_name($attr_name);
  12.          if (!empty($attr_value)) {
  13.             if ($attr_name == "vysota-matrasa-sm") {
  14.                 echo '<p class = "attr_in_loop">Высота матраса: ' . $attr_value . ' см</p>';
  15.             }
  16.             else {
  17.                 echo '<p class = "attr_in_loop">' . $attr_nice_name . ': ' . $attr_value . '</p>';
  18.             }
  19.            
  20.          }
  21.     }
  22. }
  23.  
  24. function get_attr_name($attr_slug) {
  25.     global $wpdb;
  26.     $query = $wpdb->get_results("SELECT `attribute_label` FROM wp_woocommerce_attribute_taxonomies WHERE `attribute_name` = '$attr_slug';", ARRAY_A);
  27.     return $query[0]['attribute_label'];
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement