woogc/ps/synchronize_product/ignore_meta_key
16913
wp-singular,documentation-template-default,single,single-documentation,postid-16913,wp-theme-awake,wp-child-theme-awake-child,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.8,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,wpb-js-composer js-comp-ver-8.1,vc_responsive
 

woogc/ps/synchronize_product/ignore_meta_key

WP Global Cart / woogc/ps/synchronize_product/ignore_meta_key
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

woogc/ps/synchronize_product/ignore_meta_key

Name: woogc/ps/synchronize_product/ignore_meta_key
Type: Filter
Arguments: $IgnoreMeta, $prop_title, $prop_value, $child_product, $main_product_data, $origin_product_blog_ID

The filter can be used to ignore/skip a meta field to replicate, when running a Product synchronization procedure.

The following example Skip syncing a specific meta key entirely * e.g. don’t let child products overwrite a locally-managed SEO description


function my_woogc_ignore_seo_metadesc( $ignore, $prop_title, $value, $child_product, $main_product_data, $origin_product_blog_ID ) {

    if ( '_yoast_wpseo_metadesc' === $prop_title ) {
        return TRUE;
    }

    return $ignore;
}
add_filter( 'woogc/ps/synchronize_product/ignore_meta_key', 'my_woogc_ignore_seo_metadesc', 10, 6 );

Example 2: Skip syncing the product name/title (using the core-field routing from the updated synchronize_product_data)


function my_woogc_ignore_product_title( $ignore, $prop_title, $value, $child_product, $main_product_data, $origin_product_blog_ID ) {

    if ( 'post_title' === $prop_title ) {
        return TRUE; // keep the child product's own title untouched
    }

    return $ignore;
}
add_filter( 'woogc/ps/synchronize_product/ignore_meta_key', 'my_woogc_ignore_product_title', 10, 6 );

Skip syncing status and short description together


function my_woogc_ignore_status_and_excerpt( $ignore, $prop_title, $value, $child_product, $main_product_data, $origin_product_blog_ID ) {

    $ignored_fields = array( 'post_status', 'post_excerpt' );

    if ( in_array( $prop_title, $ignored_fields, TRUE ) ) {
        return TRUE;
    }

    return $ignore;
}
add_filter( 'woogc/ps/synchronize_product/ignore_meta_key', 'my_woogc_ignore_status_and_excerpt', 10, 6 );

Conditionally ignore, based on which blog the data came from e.g. only apply price-related meta from blog ID 3


function my_woogc_ignore_price_unless_blog_three( $ignore, $prop_title, $value, $child_product, $main_product_data, $origin_product_blog_ID ) {

    $price_keys = array( '_price', '_regular_price', '_sale_price' );

    if ( in_array( $prop_title, $price_keys, TRUE ) && $origin_product_blog_ID !== 3 ) {
        return TRUE;
    }

    return $ignore;
}
add_filter( 'woogc/ps/synchronize_product/ignore_meta_key', 'my_woogc_ignore_price_unless_blog_three', 10, 6 );

Inspect $child_product before deciding e.g. never overwrite stock status if the child product is already out of stock


function my_woogc_preserve_outofstock_status( $ignore, $prop_title, $value, $child_product, $main_product_data, $origin_product_blog_ID ) {

    if ( '_stock_status' === $prop_title && $child_product->get_stock_status() === 'outofstock' ) {
        return TRUE;
    }

    return $ignore;
}
add_filter( 'woogc/ps/synchronize_product/ignore_meta_key', 'my_woogc_preserve_outofstock_status', 10, 6 );

The code should be placed inside a php file on wp-content/mu-plugins folder.

0
Would love your thoughts, please comment.x
()
x