Skip to content

Instantly share code, notes, and snippets.

View quasel's full-sized avatar
🙃
Don't worry be happy!

Bernhard quasel

🙃
Don't worry be happy!
View GitHub Profile
@quasel
quasel / gist:9df42794030519d207b6
Last active August 29, 2015 14:27 — forked from basepack/gist:09fdbdd569020e2a0ff1
WooCommerce : add custom fields to product variations v2.0
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_save_product_variation', 'save_variable_fields', 10, 1 );
/**
<?php
//set up pods::find parameters to limit to 5 items
$param = array(
'limit' => 5,
);
//create pods object
$pods = pods('pod_name', $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
@quasel
quasel / objects_arrays.md
Last active September 11, 2015 12:20 — forked from nikic/objects_arrays.md
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@quasel
quasel / custom_related_field.php
Last active September 15, 2015 08:59 — forked from Shelob9/custom_related_field.php
Get related posts from a Pods custom relationship field and show post title--as a link--and a custom field. For full explanation see: http://pods.io/tutorials/get-values-from-a-custom-relationship-field/
@quasel
quasel / register-post-type.php
Created September 23, 2015 19:10 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
/* Register custom post types on the 'init' hook. */
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 0.1.0
* @access public
@quasel
quasel / wp-api-custom-taxonomies.php
Created October 29, 2015 09:29 — forked from scottopolis/wp-api-custom-taxonomies.php
Add custom taxonomies to the WP-API
<?php
function ms_add_tax_to_api() {
$taxonomies = get_taxonomies( '', 'objects' );
foreach( $taxonomies as $taxonomy ) {
$taxonomy->show_in_rest = true;
}
}
add_action( 'init', 'ms_add_tax_to_api', 30 );
@quasel
quasel / move-proceed-to-checkout.php
Created November 7, 2015 09:41 — forked from BurlesonBrad/move-proceed-to-checkout.php
Bump the Proceed to Checkout button right next to the Update Cart button (this looks AWESOME on mobile devices!!)
add_action( 'woocommerce_cart_actions', 'move_proceed_button' );
function move_proceed_button( $checkout ) {
echo '<a href="' . esc_url( WC()->cart->get_checkout_url() ) . '" class="checkout-button button alt wc-forward" >' . __( 'Proceed to Checkout', 'woocommerce' ) . '</a>';
}
@quasel
quasel / page-resources.php
Created December 3, 2015 03:23 — forked from nicdford/page-resources.php
A Pods Example on running a loop inside a loop.
<?php
/**
* Template Name: Library Resource List
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package asotin_county_library
<?php
/**
* @package ThemeName
* @version 0.1.0
* @author Your Name <you@youremailprovider.com>
* @copyright Copyright (c) 2013, Your Name
* @link http://yoursite.com/themes/theme-slug
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
@quasel
quasel / isa-check-if-woocommerce-pa-is-tax
Created January 7, 2016 13:47 — forked from isabelc/isa-check-if-woocommerce-pa-is-tax
Check if your WooCommerce custom product attributes are taxonomies. This will show custom product attributes on your product page above the Add to Cart button. THIS WILL ALSO SHOW A NOTICE ON THE PRODUCT PAGE RIGHT UNDER THE ATTRIBUTES. THE NOTICE WILL EITHER SAY: "These ARE taxonomies." or "NOT a taxonomy."
/**
* Check if your WooCommerce custom product attributes are taxonomies.
*
* This will show custom product attributes on your product page
* above the Add to Cart button.
*
* THIS WILL ALSO SHOW A NOTICE ON THE PRODUCT PAGE
* RIGHT UNDER THE ATTRIBUTES.
*
* THE NOTICE WILL EITHER SAY: