Skip to content

Instantly share code, notes, and snippets.

View maxsherlock's full-sized avatar

Max S. maxsherlock

  • San Antonio
View GitHub Profile
@maxsherlock
maxsherlock / Custom_WP_Widget_bypassing_functions.md
Created June 24, 2016 04:41
This adds a simple custom-widget.php in your CHILD theme wp-content directory. Add the HTML code to the page you want your widget to appear: <form method='post' action="custom-widget.php"> <p class="submit"> <input type="submit" class="button-primary" value="submit" /> </p> </form>
@maxsherlock
maxsherlock / wc-tools.md
Last active June 23, 2016 02:36
Really, nice clean code to add a custom button in WooCommerce
@maxsherlock
maxsherlock / public_static_function_loop_shop_per_page.md
Last active June 23, 2016 01:32
For a WP plugin I've been developing I needed to change a plugin's value in functions.php (I'm thinking along the lines of a child theme), opposed to hard coding the actual plugin, to try and avoid issues on future updates. I just did it for an online dating company's gallery, which also increased load time speed.

Welcome!

So I'm focusing on the apply_filters method instead of changing core plugin code, this is what I did for the dating site's plugin.

// I use apply_filters() to allow a general override of values... public static function loop_shop_per_page() { $value = get_option( 'posts_per_page' ); return apply_filters('filter_loop_shop_per_page', $value); } Then, in WP functions.php (in the child theme), I'm able to select the value on for that by adding the necessary filter:

@maxsherlock
maxsherlock / woo-adding-new-fields
Created June 23, 2016 00:52
Simple, elegant code for how to add new custom fields to any WooCommerce product!
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;