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 );
}
13Jan/150

Make buttons act like buttons

By default, buttons are submits, so this should make them act actually like buttons

$('button').attr('type','button');
Filed under: HTML, jquery No Comments
13Jan/150

json_decode not working from database query

Short answer:

json_decode(html_entity_decode($json));

Had some JSON in a database that I wanted to use in my PHP code, but it keep coming up NULL.
Did a var_dump and the number of characters didn't match. Tried all sorts of trims and tried converting to utf8.
Ended up calling html_entity_decode() on the JSON string, then json_decode worked perfectly!

Filed under: PHP No Comments
3Sep/140

mySQL import dump file to RDS

mysql -h host.address.for.rds.server -u rdsusername -p rdsdatabase < backupfile.dump From http://stackoverflow.com/questions/11731714/how-do-i-import-a-local-mysql-db-to-rds-db-instance which is explains in more detail

Filed under: mySQL, RDS No Comments
13Apr/140

Cross-Browser Testing

I'm using a Mac so no IE to play with, so it got me looking around.

BrowserStack.com opens a dynamic cloud computer with whatever OS, Browser, and Resolution you would like. The remote Browser has dev tools, even Firebug Lite in IE.

You can take screenshots if you want to as well.

I used this instead of BrowserShots.com (which looks cool too, takes screenshots based on different browsers) because I needed to login to the page I was testing.

13Apr/141

jQuery attr vs prop for Checkbox

attr is iffy

$('.checkbox').attr('checked', true);      //Doesn't work
$('.checkbox').attr('checked', 'checked'); //Sometimes works
$('.checkbox').attr('checked', false);     //Works

but prop works every time

$('.checkbox').prop('checked', true);  //Works
$('.checkbox').prop('checked', false); //Works
Filed under: HTML, jquery 1 Comment
25Feb/140

What is being clicked?

Sometimes with onclick stuff isn't happening as expected so I do

$(document).on('click', function (e) {
	console.log(e.target);
});

which tells me what is receiving the click

Filed under: jquery No Comments
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
27Jan/140

Printers are Brats

Filed under: Funny 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