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 May 11, 2018 19:46
Example of modifying feed description in Google Product Feed extension
<?php
function lw_woocommerce_gpf_feed_item_google( $feed_item, $product ) {
// Modify $feed_item->description here.
return $feed_item;
}
add_filter( 'woocommerce_gpf_feed_item_google', 'lw_woocommerce_gpf_feed_item_google', 10, 2 );
@leewillis77
leewillis77 / functions.php
Last active February 7, 2023 11:43
Exclude multiple categories from the Google Product Feed
<?php
function lw_gpf_exclude_product( $excluded, $product_id, $feed_format ) {
// return TRUE to exclude this product
// return FALSE to include this product
// return $excluded to keep the standard behaviour for this product.
return $excluded;
}
@leewillis77
leewillis77 / functions.php
Created May 18, 2022 16:14
Amend the number of variations that will be included in expanded structured data
<?php
add_filter( 'woocommerce_gpf_max_variations_for_structured_data', function ($qty) {
// Modify '100' below to suit.
return 100;
});
@leewillis77
leewillis77 / functions.php
Created March 31, 2022 08:58
Modify whether an MSRP price is shown
<?php
add_filter( 'woocommerce_msrp_show_msrp_pricing', function( $show_msrp, $current_product_price, $msrp, $current_product ) {
// Modify $show_msrp here
return $show_msrp;
}, 10, 4 );
@leewillis77
leewillis77 / functions.php
Created April 26, 2021 13:11
Block emails from cart recovery (wp-cart-recovery.com)
<?php
add_filter( 'crfw_should_record_cart', function ( $record_cart, $email, $cart_details ) {
$blocked_emails = [
'foo@example.com',
];
if ( in_array( $email, $blocked_emails, true ) ) {
return false;
}
@leewillis77
leewillis77 / functions.php
Created April 3, 2020 08:18
Override whether products are excluded in the Google Product Feed
<?php
function lw_gpf_exclude_product($excluded, $product_id, $feed_format) {
// Return TRUE to specifically exclude a product
// Return FALSE to specifically include it
// Return $excluded to use the default behaviour as calculated by the extension
return $excluded;
}
add_filter( 'woocommerce_gpf_exclude_product', 'lw_gpf_exclude_product', 11, 3);
@leewillis77
leewillis77 / enable-gpf-render-cache.php
Created May 4, 2017 11:17
Enable WooCommerce Google Product Feed extension feed item cache.
<?php
/*
Plugin Name: Enable WooCommerce GPF feed item cache.
Plugin URI: http://docs.woothemes.com/document/google-product-feed/
Description: Enables feed item caching in the Google Product Feed extension.
Version: 1.0
Author: Lee Willis
Author URI: https://plugins.leewillis.co.uk/
*/
@leewillis77
leewillis77 / functions.php
Created October 5, 2020 13:16
Exclude multiple categories from Google Product Feed
<?php
function lw_gpf_exclude_product($excluded, $product_id, $feed_format) {
// Return TRUE to exclude a product, FALSE to include it, $excluded to use the default behaviour.
$cats = wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) );
// Exclude products in category ID 21
if ( in_array( 21, $cats ) ) {
return TRUE;
}
// Exclude products in category ID 22
@leewillis77
leewillis77 / functions.php
Last active September 15, 2020 08:35
Change exclusion for specific products in Google Product Feed
<?php
function lw_gpf_exclude_product($excluded, $product_id, $feed_format) {
// Do not exclude any of the specified product IDs.
if ( in_array( $product_id, [ 28 ] ) ) {
return false;
}
// Standard behaviour for all other products.
return $excluded;
}
@leewillis77
leewillis77 / functions.php
Last active September 10, 2020 12:44
Add yith_bundle to list of product types queried for in the Google Product Feed extension.
<?php
add_filter( 'woocommerce_gpf_wc_get_products_args', function ( $args ) {
$args['type'][] = 'yith_bundle';
return $args;
} );