Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Willis leewillis77

View GitHub Profile
@leewillis77
leewillis77 / functions.php
Created Apr 26, 2021
Block emails from cart recovery (wp-cart-recovery.com)
View functions.php
<?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
Last active Jun 2, 2021
Exclude multiple categories from the Google Product Feed
View functions.php
<?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 Oct 5, 2020
Exclude multiple categories from Google Product Feed
View functions.php
<?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 Sep 15, 2020
Change exclusion for specific products in Google Product Feed
View functions.php
<?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 Sep 10, 2020
Add yith_bundle to list of product types queried for in the Google Product Feed extension.
View functions.php
<?php
add_filter( 'woocommerce_gpf_wc_get_products_args', function ( $args ) {
$args['type'][] = 'yith_bundle';
return $args;
} );
@leewillis77
leewillis77 / woocommerce-product-feeds-mark-fields-as-prepopulatable.php
Created Sep 2, 2020
Mark fields as pre-populatable in the WooCommerce Product Feeds extension
View woocommerce-product-feeds-mark-fields-as-prepopulatable.php
<?php
/**
* Plugin Name: WooCommerce Product Feeds : Mark fields as pre-populatable.
* Plugin URI: https://www.ademti-software.co.uk/
* Description: Marks fields in the Google Product Feed as pre-populatable.
* Author: Ademti Software
* Version: 1.0.0
* Author URI: https://www.ademti-software.co.uk
*/
@leewillis77
leewillis77 / functions.php
Created Jul 31, 2020
Add sale status to custom label in Google Product Feed
View functions.php
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function ( $feed_item, $wc_product ) {
$feed_item->additional_elements['custom_label_4'] = [
$wc_product->is_on_sale() ? 'On Sale' : ''
];
return $feed_item;
}, 10, 2 );
@leewillis77
leewillis77 / functions.php
Created Jun 9, 2020
Add product ID to custom label in Google Product Feed
View functions.php
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function ( $feed_item, $wc_product ) {
$feed_item->additional_elements['custom_label_4'] = [ $wc_product->get_id() ];
return $feed_item;
}, 10, 2 );
@leewillis77
leewillis77 / functions.php
Created Jun 8, 2020
Disable unrecovered cart emails in WP Cart Recovery / WP Cart Recovery Pro plugin
View functions.php
<?php
// Examples of the filter to use to disable recovered cart notifications.
add_filter( 'crfw_send_recovered_cart_notifications', '__return_false' );
// Examples of the filter to use to disable unrecovered cart notifications.
add_filter( 'crfwp_send_unrecovered_cart_notifications', '__return_false' );
@leewillis77
leewillis77 / functions.php
Last active Jun 4, 2020
Example of adding fixed g:shipping tag to Google Product Feed
View functions.php
<?php
add_filter( 'woocommerce_gpf_feed_item_google', function ( $feed_item, $wc_product ) {
$feed_item->additional_elements['shipping'] = [
[
'country' => 'GB',
'region' => 'Cumbria',
'service' => 'Royal Mail',
'price' => '1.99 GBP',
]