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 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
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 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;
} );
@leewillis77
leewillis77 / woocommerce-product-feeds-mark-fields-as-prepopulatable.php
Created September 2, 2020 16:54
Mark fields as pre-populatable in the WooCommerce Product Feeds extension
<?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 July 31, 2020 07:49
Add sale status to custom label in Google Product Feed
<?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 June 9, 2020 12:14
Add product ID to custom label in Google Product Feed
<?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 );