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 June 17, 2019 08:54
Registers GTIN field from Product GTIN for WooCommerce plugin as a pre-population option.
<?php
/**
* Registers a meta field as a prepopulation option.
*/
function lw_woocommerce_gpf_custom_field_list( $list ) {
$list['meta:_wpm_gtin_code'] = 'GTIN field from Product GTIN for WooCommerce plugin';
return $list;
}
@leewillis77
leewillis77 / functions.php
Created June 19, 2019 13:02
Hardcode price for all items in Google Product Fee
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function ( $feed_item, $product ) {
// The regular price of the item.
$feed_item->regular_price_ex_tax = 1000;
$feed_item->regular_price_inc_tax = 1200;
// Set these to NULL if no sale price, or the sale price if required.
$feed_item->sale_price_ex_tax = null;
$feed_item->sale_price_inc_tax = null;
// Set these to the sale price if it exists, otherwise the regular price.
@leewillis77
leewillis77 / functions.php
Created June 26, 2019 12:59
Change shipping weight units to pounds in Google Product Feed extension.
<?php
add_filter( 'woocommerce_gpf_shipping_weight_unit', function ( $unit ) {
return 'lbs';
});
@leewillis77
leewillis77 / functions.php
Created July 9, 2019 08:00
Remove MSRP from category pages.
<?php
add_action( 'init', function() {
global $woocommerce_msrp_frontend;
remove_action( 'woocommerce_after_shop_loop_item_title', array( $woocommerce_msrp_frontend, 'show_msrp' ), 9 );
});
@leewillis77
leewillis77 / functions.php
Created August 8, 2019 14:37
Modify feed inclusion in WooCommerce Google Product Feed
<?php
add_filter( 'woocommerce_gpf_exclude_product', function ($excluded, $id, $feed_format ) {
// Return $excluded to follow the calculated logic.
// Return TRUE to exclude a product
// Return FALSE to include it.
return $excluded;
},10, 3 );
@leewillis77
leewillis77 / functions.php
Created September 3, 2019 15:00
Add alternate send times to recovery campaigns in Cart Recovery Pro for WordPress
<?php
function lw_crfwp_timing_options( $options ) {
// 259200 is the number of seconds in 72 hours.
$options[259200] = '72 Hours';
return $options;
}
add_filter( 'crfwp_timing_options', 'lw_crfwp_timing_options' );
@leewillis77
leewillis77 / functions.php
Last active October 16, 2019 04:35
Modify the product_type element in the Google Product Feed
<?php
function lw_woocommerce_gpf_feed_item_google( $feed_item, $product ) {
// Modify $feed_item->additional_elements['product_type'] here, e.g.
$feed_item->additional_elements['product_type'] = [
'Product ID ' . $product->get_id(),
];
return $feed_item;
}
add_filter( 'woocommerce_gpf_feed_item_google', 'lw_woocommerce_gpf_feed_item_google', 10, 2 );
@leewillis77
leewillis77 / functions.php
Last active October 31, 2019 20:26
Add additional option to discount expiry code options in Cart Recovery for WordPress Pro plugin
<?php
add_filter( 'crfwp_discount_code_expiry_options', function( $options ) {
$options['864000'] = array(
'value' => '864000', // Length discount code is valid for (in seconds)
'selected' => '', // Leave blank
'description' => __( 'Ten days', 'crfwp' ), // Description of discount edpiry period
);
return $options;
} );
@leewillis77
leewillis77 / functions.php
Created December 3, 2019 12:08
Modify the query args used to pull products in WooCommerce Google Product Feed plugin
<?php
add_filter( 'woocommerce_gpf_wc_get_products_args', function ($args) {
// Modify the query args here.
return $args;
});
@leewillis77
leewillis77 / function.php
Last active December 13, 2019 10:08
Control whether variations are included for products
<?php
add_filter( 'woocommerce_gpf_include_variations', function ($include_variations, $wc_product) {
// Return true if you want to include variations for this $wc_product
// Return false if you do not want to include variations for this $wc_product
// Return $include_variations to honour the standard behaviour according to the extension settings.
return $include_variations;
}, 10, 2 );