Skip to main content

Developers

Global Functions

With the following function you can check if a product is currently in an Automated Discounts session. This is helpful if you use third party plugins that need to know if a product is currently discounted.

if (function_exists( 'sgadwc_is_product_in_discount_session' )) {

$product_already_discounted = sgadwc_is_product_in_discount_session( $product_id );

// do something
}

Filters

sgadwc_sanitize_payload_product_id

info

Available since version 1.6.10

Sanitize or transform the payload product ID before validation. Use this filter to handle custom product ID formats from third-party feed plugins that are not natively supported by the plugin.

Parameters:

ParameterTypeDescription
$payload_product_idstringThe product ID from the ad payload (after built-in prefix stripping for woocommerce_gpf_ and gla_).
$current_product_idintThe current WooCommerce product ID being validated against.

Return: string|int — The sanitized product ID (can be a post ID, SKU, or cleaned identifier).

Example 1: Strip a custom prefix and return the SKU

If your feed plugin uses a format like customprefix_ABC123, you can strip the prefix and let the plugin's built-in SKU matching handle the rest:

/wp-content/themes/child-theme/functions.php
add_filter( 'sgadwc_sanitize_payload_product_id', function( $payload_id, $current_id ) {
// Transform customprefix_ABC123 → ABC123 (SKU)
if ( preg_match( '/^customprefix_(.+)$/', $payload_id, $matches ) ) {
return $matches[1];
}
return $payload_id;
}, 10, 2 );

Example 2: Convert custom format to WooCommerce Post ID

If you need to look up the product by SKU and return the actual WooCommerce Post ID:

/wp-content/themes/child-theme/functions.php
add_filter( 'sgadwc_sanitize_payload_product_id', function( $payload_id, $current_id ) {
// Transform customprefix_ABC123 → WooCommerce Post ID
if ( preg_match( '/^customprefix_(.+)$/', $payload_id, $matches ) ) {
$sku = $matches[1];
$product_id = wc_get_product_id_by_sku( $sku );
if ( $product_id ) {
return $product_id;
}
}
return $payload_id;
}, 10, 2 );
tip

Use Example 1 if your SKUs are unique across all products including variations. Use Example 2 if you need more precise matching or if your variations share SKUs with parent products.

Boost your sales with Google Shopping ads. Allow Google to set your discount to secure the sale and optimize your profit margin.