Skip to content

Instantly share code, notes, and snippets.

View danielucas's full-sized avatar

Daniel Lucas danielucas

View GitHub Profile
@PhilippSchreiber
PhilippSchreiber / wp_prepare_attachment_for_js.php
Created September 26, 2013 10:56
Modify the image URL used in Wordpress Media Frame.
function ps_wp_prepare_attachment_for_js($response, $attachment, $meta) {
if($response['type'] == 'image') {
$image_src = wp_get_attachment_image_src( $response['id'], 'thumbnail' ); //Use any image size added to your wordpress installation
if( is_array($image_src) ) {
$response['url'] = $image_src[0];
}
}
return $response;
@jackgregory
jackgregory / functions.php
Last active December 15, 2015 22:58
WooCommerce - Disable and add 'sold out' to a single WooCommerce product variation dropdown
add_action( 'woocommerce_before_add_to_cart_form', 'woocommerce_variations_sold_out_filter' );
function woocommerce_variations_sold_out_filter() {
// disable and add "sold out" to product variations
wc_enqueue_js( '
var product_variations = $( "form.variations_form" ).data( "product_variations" );
// dont disable with multiple drop-downs
if ( product_variations && $( "form.variations_form" ).find( "select" ).length === 1 ) {
var attribute_name = $( "form.variations_form" ).find( "select" ).attr( "name" );
$.each( product_variations, function( key, value ) {