Last active
December 4, 2023 14:58
-
-
Save steve10287/c7b64daa819c8f218c6bddca4e6bb14f to your computer and use it in GitHub Desktop.
Disable Polylang Variation Sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Plugin name: Disable Polylang Variation Sync | |
Plugin URI: https://designamite.co.uk | |
Version: 0.2 | |
Author: Steven Brown | |
Author uri: https://designamite.co.uk | |
Description: Removes actions that sync product variation data | |
WC requires at least: 3.0 | |
WC tested up to: 3.7 | |
*/ | |
/** | |
* Disable variation sync | |
*/ | |
add_action( 'pll_init', function() { | |
// Disable variaton sync | |
remove_action( 'add_meta_boxes', array( PLLWC()->admin_products, 'add_meta_boxes' ), 5, 2 ); | |
remove_action( 'woocommerce_update_product', array( PLLWC()->admin_products, 'save_product' ) ); | |
remove_action( 'woocommerce_new_product_variation', array( PLLWC()->admin_products, 'save_variation' ) ); | |
remove_action( 'woocommerce_update_product_variation', array( PLLWC()->admin_products, 'save_variation' ) ); | |
remove_action( 'pll_created_sync_post', array( PLLWC()->admin_products, 'copy_variations' ) ); | |
// Removes global attribute sync / product type | |
remove_filter( 'pll_copy_taxonomies', array( PLLWC()->post_types, 'copy_taxonomies' ) ); | |
}, 999 ); | |
// Product taxonomy filter, disable attributes from copying over and keep what we need | |
add_filter( 'pll_copy_taxonomies', 'rp_pll_copy_taxonomies', 10, 2); | |
function rp_pll_copy_taxonomies($taxonomies) { | |
if (in_array('product_cat', $taxonomies)) { | |
$taxonomies = array('product_cat', 'product_tag'); | |
} | |
return $taxonomies; | |
} | |
add_filter('pllwc_copy_post_metas', 'pll_mc_remove_metadata_sync', 10, 5); | |
/** | |
* Polylang Syncing | |
* Don't sync price / stock-related information in Polylang for WC | |
*/ | |
function pll_mc_remove_metadata_sync($to_copy, $sync, $from, $to, $lang) { | |
$remove_fields = array( | |
'_backorders', | |
'_featured', | |
'_manage_stock', | |
'_max_price_variation_id', | |
'_max_regular_price_variation_id', | |
'_max_sale_price_variation_id', | |
'_max_variation_price', | |
'_max_variation_regular_price', | |
'_max_variation_sale_price', | |
'_min_price_variation_id', | |
'_min_regular_price_variation_id', | |
'_min_sale_price_variation_id', | |
'_min_variation_price', | |
'_min_variation_regular_price', | |
'_min_variation_sale_price', | |
'_regular_price', | |
'_sale_price', | |
'_sale_price_dates_from', | |
'_sale_price_dates_to', | |
'_sold_individually', | |
'_tax_class', | |
'_tax_status', | |
'_price', | |
'_stock', | |
'_stock_status', | |
'_tax_class', | |
'_tax_status', | |
'_visibility', | |
'total_sales', | |
'_default_attributes', | |
'_product_attributes' | |
); | |
foreach($remove_fields as $key_num => $key_to_remove) { | |
if(($key = array_search($key_to_remove, $to_copy)) !== false) { | |
unset($to_copy[$key]); | |
} | |
} | |
return $to_copy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment