Skip to content

Instantly share code, notes, and snippets.

@coenjacobs
coenjacobs / wc-custom-product-order.php
Created June 18, 2013 09:32
Adds a custom way of ordering products, in this example it's 'random' product ordering. This can also be set to be used as default via the Catalog tab in WooCommerce settings.
<?php
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'random_list' == $orderby_value ) {
$args['orderby'] = 'rand';
$args['order'] = '';
<?php
$result = wp_remote_get('yourredirectingdomain.com');
$history = $result['http_response']->get_response_object()->history;
foreach( $history as $part ) {
echo $part->headers->getValues('location');
}
@coenjacobs
coenjacobs / wc-attribute-links.php
Created May 4, 2012 14:05
Display WooCommerce product attribute archive links on product page, right below the add to cart button.
@coenjacobs
coenjacobs / gist:3714838
Created September 13, 2012 14:55
Make the phone number not required in WooCommerce checkout
<?php
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
?>
<?php
class Object {
public function setup() {
add_action('init', array($this, 'init') );
}
}
<?php
class MetaChecker {
public function checkMeta( WP_Post $post ) {
$value = get_post_meta($post->ID, 'key_of_value_store', true);
// @TODO: Do magic with $value
}
}
@coenjacobs
coenjacobs / gist:2510177
Created April 27, 2012 15:30
Allow HTML in term (category, tag) descriptions
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
}
foreach ( array( 'term_description' ) as $filter ) {
remove_filter( $filter, 'wp_kses_data' );
}
<?php
namespace CoenJacobs\StefExample\PostTypes;
abstract class AbstractType {
public function setup() {
// possibly some setup logic here?
}
public function register() {
@coenjacobs
coenjacobs / wc-show-dimensions-on-archive.php
Created May 4, 2012 14:02
Display WooCommerce product dimensions on archive pages, right below the title of the product
<?php
/*
Plugin Name: WooCommerce Show Dimensions On Archive
Description: Display product dimensions on archive pages, right below the title of the product.
Version: 1.0
Author: Coen Jacobs
Author URI: http://coenjacobs.me
*/
@coenjacobs
coenjacobs / wc-shop-loop-columns.php
Created February 15, 2014 22:39
Change the number of columns in which products will be shown on product archives
<?php
add_filter( 'loop_shop_columns', 'wc_loop_shop_columns', 1, 10 );
/*
* Return a new number of maximum columns for shop archives
* @param int Original value
* @return int New number of columns
*/
function wc_loop_shop_columns( $number_columns ) {