Skip to content

Instantly share code, notes, and snippets.

View leewillis77's full-sized avatar

Lee Willis leewillis77

View GitHub Profile
@leewillis77
leewillis77 / functions.php
Created March 23, 2018 13:22
Hide attribute labels on variable products in Google Product Feed titles
<?php
add_filter( 'woocommerce_gpf_include_attribute_labels_in_title', '__return_false' );
@leewillis77
leewillis77 / functions.php
Created March 25, 2018 16:50
Add additional duration to Cart Recovery for WordPress Pro
<?php
function lw_crfwp_timing_options($options) {
$options['604800'] = __( 'One week', 'crwfp' );
return $options;
}
add_filter( 'crfwp_timing_options', 'lw_crfwp_timing_options' );
@leewillis77
leewillis77 / functions.php
Created April 25, 2018 13:59
Remove all shipping dimensions from Google Product Feed
<?php
function lw_gpf_remove_shipping_attrs($elements, $product_id) {
unset($elements['shipping_width']);
unset($elements['shipping_length']);
unset($elements['shipping_height']);
return $elements;
}
add_filter( 'woocommerce_gpf_elements_google', 'lw_gpf_remove_shipping_attrs', 11, 2 );
@leewillis77
leewillis77 / functions.php
Created April 30, 2018 14:14
Remove shipping weight from Google Product Feed
<?php
function lw_exclude_shipping_weight( $feed_item ) {
$feed_item->shipping_weight = null;
return $feed_item;
}
add_filter( 'woocommerce_gpf_feed_item_google', 'lw_exclude_shipping_weight' );
@leewillis77
leewillis77 / functions.php
Created July 31, 2018 15:04
Add custom label to Google Product Feed item
<?php
function lw_woocommerce_gpf_feed_item_google( $feed_item, $product ) {
$feed_item->additional_elements['custom_label_0'] = array( 'My custom label' );
return $feed_item;
}
add_filter( 'woocommerce_gpf_feed_item_google', 'lw_woocommerce_gpf_feed_item_google', 10, 2 );
@leewillis77
leewillis77 / gist:8348193
Last active October 25, 2018 15:25
How to use config values in Codeception tests?

I'm currently looking at using Codeception to test WordPress plugins. I've got most things set up how I'd like, but there's one final step that doesn't feel right. Because the tests will be distributed, and I want anyone to be able to run them on an install of their choosing some of the "config" for the tests needs to be easily changeable.

So - I need the real config to not be stored in version control. For site URL that's straightforward, I can not distribute the acceptance.suite.yml and instead distribute a sample file that the user can copy to acceptance.suite.yml and customise as appropriate.

However - my tests also need some other config that I'd want to be outside of version control. Ideally I'd add this config to the same YML file, but I need to be able to access it from the tests, e.g.

acceptance.suite.yml:

class_name: WebGuy
modules:
@leewillis77
leewillis77 / functions.php
Created February 21, 2019 14:55
Example of modifying item_group_id
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function( $feed_item, $product ) {
// Modify $feed_item->item_group_id here
return $feed_item;
}, 10, 2 );
@leewillis77
leewillis77 / functions.php
Created February 25, 2019 09:38
Example of modifying image links sent in Google Product Feed
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function( $feed_item, $product ) {
// Modify $feed_item->image_link and/or $feed_item->additional_images here.
return $feed_item;
}, 10, 2 );
@leewillis77
leewillis77 / functions.php
Created February 25, 2019 09:41
Avoid issues with extensions that abuse the_content filter
<?php
add_filter( 'woocommerce_gpf_title', function ( $title, $specific_id ) {
global $post, $gpf_original_post;
$gpf_original_post = $post;
$post = get_post( $specific_id );
setup_postdata( $post );
return $title;
}, 10, 2 );
@leewillis77
leewillis77 / functions.php
Created March 28, 2019 14:51
Make the GTIN field from WooCommerce Germanized available as a prepopulation option
<?php
/**
* Registers a meta field with key _ts_gtin as a prepopulation option
*/
function lw_woocommerce_gpf_custom_field_list( $list ) {
$list['meta:_ts_gtin'] = 'GTIN field from WooCommerce Germanized';
return $list;
}
add_filter( 'woocommerce_gpf_custom_field_list', 'lw_woocommerce_gpf_custom_field_list' );