Skip to content

Instantly share code, notes, and snippets.

View rfmeier's full-sized avatar
💭
Nada.

Ryan Meier rfmeier

💭
Nada.
View GitHub Profile
@rfmeier
rfmeier / example.php
Created November 7, 2017 17:21
Get all orders for a product in WooCommerce.
<?php
/**
* Get all orders given a product.
*
* @param integer $product_id The product ID.
*
* @return array An array of WC_Order objects.
*/
function rfm_get_orders_by_product( $product_id ) {
@rfmeier
rfmeier / example.sql
Created November 7, 2017 03:29
Select all orders for a product with MySql
SELECT
`items`.`order_id`,
MAX(CASE WHEN `itemmeta`.`meta_key` = '_product_id' THEN `itemmeta`.`meta_value` END) AS `product_id`
FROM
`wp_woocommerce_order_items` AS `items`
INNER JOIN
`wp_woocommerce_order_itemmeta` AS `itemmeta`
ON
`items`.`order_item_id` = `itemmeta`.`order_item_id`
WHERE
@rfmeier
rfmeier / functions.php
Last active November 7, 2017 03:52
Display full content width for a single woocommerce product in Genesis
<?php
add_filter( 'genesis_site_layout', 'sample_genesis_site_layout' );
/**
* Callback for 'genesis_site_layout' filter.
*
* Force full width content on the single product page.
*
* @param $layout The layout slug.
* @return string The layout slug.
@rfmeier
rfmeier / .htaccess
Created January 20, 2016 19:17
Force https in .htaccess
# force https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# end force https
@rfmeier
rfmeier / wp-config.php
Created January 20, 2016 19:13
Force SSL within the WordPress admin
<?php //* do not include php tag
define( 'FORCE_SSL_ADMIN', true );
@rfmeier
rfmeier / functions.php
Last active January 20, 2016 20:48
Authenticate callback for WordPress register_meta() function.
<?php //* do not include php tag
/**
* Callback for WordPress register_meta() sanitize parameter.
*
* Determine if the current meta key and value should be visible within the
* WordPress post editor Custom Fields meta box.
*
* @see https://codex.wordpress.org/Function_Reference/register_meta
*
@rfmeier
rfmeier / functions.php
Last active October 24, 2021 21:37
Sanitize callback for WordPress register_meta() function.
<?php //* do not include php tag
/**
* Callback for WordPress register_meta() sanitize parameter.
*
* Sanitize the 'sample_count' meta value before saved to the database.
*
* @see https://codex.wordpress.org/Function_Reference/register_meta
*
* @uses absint()
@rfmeier
rfmeier / functions.php
Last active January 20, 2016 20:48
Hook register_meta() into WordPress 'init'
<?php //* do not include php tag
add_action( 'init', 'register_my_sample_meta' );
/**
* Callback for WordPress 'init' action.
*
* Register the post meta.
*
* @uses register_meta()
* @see https://codex.wordpress.org/Function_Reference/register_meta
@rfmeier
rfmeier / sample.php
Created January 8, 2016 21:50
Use the custom archive setting to modify the number of posts on a custom post type archive page.
<?php
/**
* Use the custom archive setting to modify the number of posts on a custom post type archive page.
*/
add_action( 'pre_get_posts', 'cpt_as_pre_get_posts' );
/**
* Callback for WordPress 'pre_get_posts' action.
*
* Modify the number of posts on an testimony archive page if set to a custom value.
@rfmeier
rfmeier / sample.php
Created January 8, 2016 21:49
Display the custom meta box content with the post type 'testimony' archive settings
<?php
/**
* Display the custom meta box content with the post type 'testimony' archive settings.
*/
/**
* Callback for WordPress add_meta_box() function parameter.
*
* Display the custom meta box content with the post type 'testimony' archive settings.
*