New Landing How can we help? Themeforest Theme Support Neighborhood overriding sf_mini_product_items() function within a child theme

Viewing 13 posts - 1 through 13 (of 13 total)
  • #156508
    lellis690
    Member
    Post count: 8

    Hi – I want to change the dimensions of the mini-images used displayed on the Home Page. I’ve edited the sf-products.php file and the changes appeared as they should.

    However in order to preserve the change after future theme updates, I want to include the change within the child theme.

    This post indicates that simply adding the altered sf-products.php file to the child theme will work. However in my case this isn’t true. Do I have to recreate the same folder structure?

    #156512
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please copy the sf_mini_product_items() function from sf-products.php and paste at functions.php of child theme to avoid any theme upgrade issue.
    Thanks
    Mohammad

    #156532
    lellis690
    Member
    Post count: 8

    Thank 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?

    #156533
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You need to copy the full function from parent theme and paste at functions.php of child theme. Make sure that you warpzped the code like <?php //your code ?>.

    Thanks
    Mohammad

    #156540
    lellis690
    Member
    Post count: 8

    Hi – 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?

    #156561
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Where is the code of function start like function sf_mini_product_items(?
    Thanks
    Mohammad

    #156586
    lellis690
    Member
    Post count: 8

    As I said, I’m not very experienced in overriding functions. Do I need to add some extra code at the beginning?

    #156621
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please attach here changed sf-products.php file and provide me wordpress admin login detail after installing WPIDE plugin.
    Thanks
    Mohammad

    #156627
    lellis690
    Member
    Post count: 8
    This reply has been marked as private.
    #156628
    lellis690
    Member
    Post count: 8
    This reply has been marked as private.
    #156759
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    I need FTP login detail to resolve this issue.
    Thanks
    Mohammad

    #156936
    lellis690
    Member
    Post count: 8
    This reply has been marked as private.
    #156937
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    ok. Let us know.
    -Rui

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register