mrkeck Sharing the Love

4Feb/150

WooCommerce get Quantity of Items Purchased by a User

Get any Attribute for a User Grouped by Item or One Specific Item for use in WordPress Plugin

//UserId, Attribute, [Specific Item]
//Attribute will prepend '_' if left off to make it more readable
$qtyForAllItemsUserPurchased = wooAttr(get_current_user_id(), 'qty');
$qtyForOneItemUserPurchased = wooAttr(get_current_user_id(), 'qty', "Example Item 123");
 
function wooAttr( $user, $attr, $item = NULL ){
	global $wpdb;
	if( substr($attr, 0, 1) != '_' ){
		$attr = '_' . $attr;
	}
	if(is_null($item)){
		$sql = $wpdb->prepare("SELECT oi.order_item_name item, SUM(oim.meta_value) val FROM wp_posts p JOIN wp_woocommerce_order_items oi ON p.ID = oi.order_id JOIN wp_woocommerce_order_itemmeta oim ON oi.order_item_id = oim.order_item_id WHERE oim.meta_key = %s AND p.post_author = %d GROUP BY item", $attr, $user);
	}else{
		$sql = $wpdb->prepare("SELECT oi.order_item_name item, SUM(oim.meta_value) val FROM wp_posts p JOIN wp_woocommerce_order_items oi ON p.ID = oi.order_id JOIN wp_woocommerce_order_itemmeta oim ON oi.order_item_id = oim.order_item_id WHERE oim.meta_key = %s AND p.post_author = %d AND oi.order_item_name = %s GROUP BY item", $attr, $user, $item);
	}
	return $wpdb->get_results( $sql , ARRAY_A );
}
27Jan/140

Iframe in WordPress not working

I used a plugin called "Pageview" after struggling for hours trying to get Iframes working.

Very easy and worked great! Took about 1 min

http://urbangiraffe.com/plugins/pageview/

Filed under: wordpress No Comments
23Jan/140

WordPress Custom Login

This is site explains how to easily customize the login screen without using any plugins.

http://wp.smashingmagazine.com/2012/05/17/customize-wordpress-admin-easily/

If you are using a child theme, you will need a slight code change from the link above.
Use "get_stylesheet_directory_uri()" instead of "get_template_directory_uri()"

Filed under: wordpress No Comments
19Jan/140

Make the ellipsis clickable in WordPress

At the end of the excerpt summary it has a [...] but it doesn't link to anything. The code below makes it a link and changes [...] to [Read More].

Add this code to the functions.php

function replace_ellip($content) {
  return str_replace('[…]',
    '<a href="'. get_permalink() .'" class="more-link">[Read More]</a>',
      $content
  );
}
add_filter('the_excerpt', 'replace_ellip');
Filed under: PHP, wordpress No Comments
29Nov/122

WordPress Theme simpleCorp Slider Only Shows One Slide (Fixed)

simpleCorp slider was broken because it only showed one slide instead of all the ones in the list.
To fix change one line in /wp-content/themes/simplecorp/homepage-slider.php

//Take out
//$wp_query = new WP_Query('post_type=featured&orderby=menu_order&order=ASC&sliders='. $slider);
//Add next line
$wp_query = new WP_Query('posts_per_page=10&post_type=featured&orderby=menu_order&order=ASC&sliders='. $slider);
Filed under: wordpress 2 Comments
28Nov/120

WordPress Theme Not Recognizing Static Front Page as Home Page

I created a page called "Home" and set it as my Static Front Page (make it my home page).
But the theme I am using simpleCorp doesn't recognize my static front page as being the home page.

So I changed the page.php in the theme folder (/wp-content/themes/theThemeYouAreUsing/) to see if the current page is set as the front page and if it is then use home.php instead. The code is easier than it may sound.
Just add

<?php
	if(is_front_page()){
		//echo "We are home";
		include ('home.php');
	}else{
		//echo "Nope";
 ?>

Right below:

<?php get_header(); ?>

Then make sure you add:

<?php } ?>

Directly above:

<?php get_footer(); ?>

at the bottom of page.php.

That's it!

Filed under: wordpress No Comments
27Nov/120

WordPress Maximum Upload Size on Dreamhost

I kept getting "Maximum upload file size: 7MB". I read abunch of articles about php.ini in wp-admin and ini_set but nothing worked except this article:
Sounded a little scary but was super easy and worked great!
http://www.bluesunray.com/wordpress-tips/how-to-increase-upload-max-file-size-for-dreamhost

Filed under: wordpress No Comments