Digital experiences for all disciplines
Forum Replies Created
-
Posted in: We hit Power Elite.
-
Thank you for the prompt confirmation.
Yes, however I was going to start it on a new thread rather than confuse this one.
It seems there may be a bug in the way Woocommerce displays the bestsellers. I’ve contacted them for advice.
March 12, 2015 at 5:23 pm in reply to: overriding sf_mini_product_items() function within a child theme #156936This reply has been marked as private.March 11, 2015 at 5:24 pm in reply to: overriding sf_mini_product_items() function within a child theme #156628This reply has been marked as private.March 11, 2015 at 5:22 pm in reply to: overriding sf_mini_product_items() function within a child theme #156627This reply has been marked as private.March 11, 2015 at 3:15 pm in reply to: overriding sf_mini_product_items() function within a child theme #156586As I said, I’m not very experienced in overriding functions. Do I need to add some extra code at the beginning?
March 11, 2015 at 1:39 pm in reply to: overriding sf_mini_product_items() function within a child theme #156540Hi – I’m clearly doing something wrong as I’m getting the same issue (I’m not that experienced in this type of thing). I’ve reproduced the entire functions.php I’m using below:
<?php // Ensure visibility if ( ! $product->is_visible() ) return; if ( has_post_thumbnail() ) { $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) ); $image_link = wp_get_attachment_url( get_post_thumbnail_id() ); $image = aq_resize( $image_link, 70, 91, true, false); if ($image) { $image_html = '<img itemprop="image" src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" alt="'.$image_title.'" />'; } else { $image_html = '<img itemprop="image" src="'.$image_link.'" width="70" height="91" alt="'.$image_title.'" />'; } } if ( comments_open() ) { $count = $wpdb->get_var(" SELECT COUNT(meta_value) FROM $wpdb->commentmeta LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE meta_key = 'rating' AND comment_post_ID = $post->ID AND comment_approved = '1' AND meta_value > 0 "); $rating = $wpdb->get_var(" SELECT SUM(meta_value) FROM $wpdb->commentmeta LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE meta_key = 'rating' AND comment_post_ID = $post->ID AND comment_approved = '1' "); if ( $count > 0 ) { $average = number_format($rating / $count, 2); $rating_output = '<div class="star-rating" title="'.sprintf(__('Rated %s out of 5', 'swiftframework'), $average).'" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"><span style="width:'.($average*16).'px"><span itemprop="ratingValue" class="rating">'.$average.'</span> '.__('out of 5', 'swiftframework').'</span></div>'; } } $product_output .= '<li class="clearfix" itemscope itemtype="http://schema.org/Product">'; if ($image) { $product_output .= '<figure>'; $product_output .= '<a href="'.get_permalink($post->ID).'">'; $product_output .= $image_html; $product_output .= '</a>'; $product_output .= '</figure>'; } $product_output .= '<div class="product-details">'; $product_output .= '<h5 itemprop="name"><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></h5>'; if ($asset_type == "top-rated") { $product_output .= $rating_output; } else { $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) ); $product_output .= $product->get_categories( ', ', '<span class="product-cats">' . _n( '', '', $size, 'swiftframework' ) . ' ', '</span>' ); } if (!$catalog_mode) { $product_output .= '<span class="price" itemprop="price">'.$product->get_price_html().'</span>'; } $product_output .= '</div>'; $product_output .= '</li>'; $product_list_output .= $product_output; endwhile; wp_reset_query(); wp_reset_postdata(); remove_filter( 'posts_clauses', array( $woocommerce->query, 'order_by_rating_post_clauses' ) ); $product_list_output .= '</ul>'; return $product_list_output; } } if ( ! function_exists( 'sf_product_items' ) ) { function sf_product_items($asset_type, $category, $carousel, $product_size, $item_count, $width) { global $woocommerce, $woocommerce_loop; $args = array(); global $sidebars; $columns = 4; if ($sidebars == "no-sidebars") { if ($width == "3/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 ); $columns = 3; } else if ($width == "1/2") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 2 ); $columns = 2; } else if ($width == "1/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 1 ); $columns = 1; } else { if ($product_size == "mini") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 6 ); $columns = 6; } else { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 ); } } } else if ($sidebars == "one-sidebar") { if ($width == "3/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 ); $columns = 3; } else if ($width == "1/2") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 2 ); $columns = 2; } else if ($width == "1/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 1 ); $columns = 1; } else { if ($product_size == "mini") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 ); } else { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 ); $columns = 3; } } } else { if ($width == "3/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 2 ); $columns = 2; } else if ($width == "1/2") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 1 ); $columns = 1; } else if ($width == "1/4") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 1 ); $columns = 1; } else { if ($product_size == "mini") { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 ); $columns = 3; } else { $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 2 ); $columns = 2; } } } ?>
Can you tell me what I’m missing?
March 11, 2015 at 1:16 pm in reply to: overriding sf_mini_product_items() function within a child theme #156532Thank you for such a speedy response!
I’ve created a functions.php file, added the changes and uploaded to the child theme. The website then shows a blank page. Clearly I’m not adding enough code or what I have added is incorrect. The bit I want to change is:
if ( ! $product->is_visible() ) return; if ( has_post_thumbnail() ) { $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) ); $image_link = wp_get_attachment_url( get_post_thumbnail_id() ); $image = aq_resize( $image_link, 70, 91, true, false); if ($image) { $image_html = '<img itemprop="image" src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" alt="'.$image_title.'" />'; } else { $image_html = '<img itemprop="image" src="'.$image_link.'" width="70" height="91" alt="'.$image_title.'" />'; } }
Can you tell me what I need to add to functions.php to do this?
-
Posted in: We hit Power Elite.