facebook-for-woocommerce
facebook-for-woocommerce copied to clipboard
Add filter to dynamically change FB price meta
I used the Woo filters woocommerce_product_get_sale_price and woocommerce_product_variation_get_sale_price, to dynamically set a price for FB, but you have made quite a few undocumented changes in the plugin recently.
So these filters are now being ignored, in favor of the custom meta fb_product_price, that I still have to hook to the filters... but it's now causing slow performance, as for every load I need to update_post_meta.
Can you please add a custom filter, when you are checking for the fb_product_price?
Here an example for dynamically setting prices and current solution found.
Thank you
Hey @Jany-M,
In version 2.0.0 of our plugin we added a new filter that might be good for you here.
/**
* Filters the product price used for Facebook sync.
*
* @since 2.0.0-dev.1
*
* @param int $price product price in cents
* @param float $facebook_price user defined facebook price
* @param \WC_Product $product product object
*/
return (int) apply_filters( 'wc_facebook_product_price', $price, (float) $facebook_price, $product );
If that doesn't quite meet your needs, the complete data that we're sending to Facebook is also filterable instead:
/**
* Filters the generated product data.
*
* @param int $id Woocommerce product id
* @param array $product_data An array of product data
*/
return apply_filters(
'facebook_for_woocommerce_integration_prepare_product',
$product_data,
$id
);
which should also make it possible to filter the data with your current functions. Would either of these be okay for you?
Cheers,
Simon.
@simonporter007 thank you for the update! Would it be possible to debug this, in a easier way, from within the product edit page? A FB sync box debug metabox where we can check what data for that product will be processed/sync?
@Jany-M I think this would be a little tricky with the filters available, and the third-party code that could get called throughout the data gathering process. The debug log would be able to show you what values were sent though.
As the plugin is mainly catering towards merchants with a hands-off approach, I'm not sure a debug metabox is something we'd be looking to add at this time, though thanks for the feedback! I've made a note of this for the product team to review.
Is there anything else I can help out with today?
Cheers!
Hi, is there a way to override the sale price sent to facebook? I'm using the plugin woo discount rules which doesn't actually save a sale price. For now I'm using this filter but it overrides directly the regular price sent to facebook:
function odb_facebook_sync_price_update($price, $facebook_price, $product){ if ( ! $facebook_price && $product instanceof \WC_Product ) { $price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, 1, $price, 'discounted_price', true, true); } return $price; } add_filter( 'wc_facebook_product_price', 'odb_facebook_sync_price_update', 10, 3 );
I would like to keep the regular price as is and override the sale price which is actually not set in the product by the discount rules plugin.
Thank you
@MicPass,
The complete data we send to Facebook is filterable with facebook_for_woocommerce_integration_prepare_product.
You can modify the sales price in $product_data['sale_price'].
I'll close this issue as the initial query has been addressed. Feel free to re-open if you have any more queries.