• Jason

    (@galapogos01)


    Hello Devs,

    It has come to my attention that the attribute mapper feature in Facebook for WooCommerce copies attributes already configured against the product (eg. pa_colour), creates a new custom attribute (eg. fb_colour) and populates it with the same information. It does this for each attribute mapped (ie. n times).

    We have over 7k products each with multiple attributes and this code is duplicating each attribute for each product (ie. n * num_products). As you’d know, postmeta is one of the hottest tables in WooCommerce and adding additional postmeta for no reason is wasteful.

    What developer thought this was a good idea?

    Why would you not use the mapping to pull existing attributes?

    When can this be fixed?

    • This topic was modified 3 months, 1 week ago by Jason.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Jason

    (@galapogos01)

    Worse still; the plugin sets 13 postmeta records for each product, even when the mapping is empty!

    • fb_age_group
    • fb_brand
    • fb_color
    • fb_gender
    • fb_material
    • fb_mpn
    • fb_pattern
    • fb_product_condition
    • fb_product_description
    • fb_product_video
    • fb_rich_text_description
    • fb_size
    • fb_visibility

    This is madness — can you advise how this can be stopped?

    Thread Starter Jason

    (@galapogos01)

    For anyone following — this patch bypasses saving the superfluous meta:

    --- a/facebook-commerce.php
    +++ b/facebook-commerce.php
    @@ -1004,6 +1004,8 @@
    * @param WC_Facebook_Product $woo_product The Facebook product object
    */
    private function save_facebook_product_attributes( $woo_product ) {
    + // Disabled: rely on defaults.
    + return;
    // phpcs:disable WordPress.Security.NonceVerification.Missing
    if ( isset( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) {
    $woo_product->set_fb_brand( sanitize_text_field( wp_unslash( $_POST[ WC_Facebook_Product::FB_BRAND ] ) ) );

    Would love to see a proper fix to this in core; only save them if populated, for example! Think of your poor customers’ performance…

    Plugin Support Marija

    (@marijastuntcoders)

    Hi @galapogos01 – thank you for reaching out!

    We have prioritized this issue, and the team is looking into it. We will let you know as soon as we have an update.

    Kind regards,
    Marija

    Thread Starter Jason

    (@galapogos01)

    Thanks @marijastuntcoders

    I found I also had to patch these methods to avoid further superfluous meta records being created:

    --- a/facebook-commerce.php
    +++ b/facebook-commerce.php
    @@ -1071,6 +1071,8 @@
    * @since 1.10.0
    */
    private function save_product_settings( WC_Product $product ) {
    + // Disabled: rely on defaults.
    + return;
    $woo_product = new WC_Facebook_Product( $product->get_id() );

    // phpcs:disable WordPress.Security.NonceVerification.Missing

    And

    --- a/includes/Products.php
    +++ b/includes/Products.php
    @@ -299,6 +299,9 @@
    * @return bool success
    */
    public static function set_product_visibility( \WC_Product $product, $visibility ) {
    + // Disabled: rely on default (visible).
    + return true;
    +
    unset( self::$products_visibility[ $product->get_id() ] );
    if ( ! is_bool( $visibility ) ) {
    return false;

    These patches are just butchering methods to avoid creating meta records. It would be excellent to see the plugin properly updated to avoid creating these records where the product is just using default values. ie. where the value is not set, the plugin should skip saving a meta.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.