Skip to content

Instantly share code, notes, and snippets.

@gspearce
gspearce / woocommerce_product_variables.php
Last active May 19, 2016 14:06
Get WooCommerce Product Variables in $post Form
<?php
// lets talk variations here
$available_variations = $product->get_available_variations();
foreach($available_variations as $prod_variation) {
$post_id = $prod_variation['variation_id'];
$post_object = get_post($post_id);
// do what you like with the post object here
// you can add the variation to the product cart by linking to ?add-to-cart={variation_id}&quantity=xxx
echo $post_object->post_title;
}
@gspearce
gspearce / genesis_options_functions.php
Created September 3, 2013 16:10
Genesis: Add Options to "Theme Options" page
<?php
// first we register the defaults
function iamp_defaults($defaults) {
$defaults['option1'] = '';
$defaults['option2'] = '';
return $defaults;
}
@gspearce
gspearce / genesis_set_full_width.php
Created September 9, 2013 19:40
Genesis: Set full page width.
<?php
/* You probably won't need to include the opening and closing PHP tags. */
add_action('genesis_pre_get_option_site_layout', 'iampmedia_home_page_layout' );
function iampmedia_home_page_layout() {
return 'full-width-content';
}
// for more information, see http://snippetpress.com/genesis/genesis-force-full-width-layout-for-a-single-page/
@gspearce
gspearce / extract_shortcode_atts.php
Created September 10, 2013 13:49
Extracts shortcode attributes.
<?php
// do not include the opening PHP tag
extract( shortcode_atts( array(
'title' => 'no title',
'something' => 'value',
), $atts,) );
?>
@gspearce
gspearce / post_titles_only.php
Created September 19, 2013 17:30
Display only post titles on category archive
<?php
/* do not include opening PHP brackets.
Add this content to your category.php file */
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
?>
@gspearce
gspearce / woocommerce_show_all_posts.php
Created October 15, 2013 21:55
WooCommerce snippet to create a view all products option for every category or search result page.
<?php
/* Don't forget to remove the opening and closing PHP tags */
if( isset( $_GET['show_all'] ) ){
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ) );
} else {
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 10;' ) );
}
@gspearce
gspearce / date_query.php
Created January 20, 2014 10:59
Date query future
'date_query' => array(
array(
'after' => 'today',
'inclusive' => true,
),