Skip to content

Instantly share code, notes, and snippets.

@agustinprosperi
Last active September 1, 2015 10:02
Show Gist options
  • Save agustinprosperi/b3f1256a294b28382eaf to your computer and use it in GitHub Desktop.
Save agustinprosperi/b3f1256a294b28382eaf to your computer and use it in GitHub Desktop.
If you are using WPML with WooCommerce Multilingual, WooCommerce & Composite Products and get an error when attempting to add a Composite to your cart, this snippet might fix the issue.
<?php
/**
* Plugin Name: WooCommerce Composite Products - WPML Cart Error Fix
* Plugin URI: http://www.woothemes.com/products/composite-products/
* Description: If you are using WPML with WooCommerce Multilingual, WooCommerce & Composite Products and get an error when attempting to add a Composite to your cart, this snippet might fix the issue.
* Version: 1.1
* Author: Manos Psychogyiopoulos
* Author URI: http://www.somewherewarm.net/
*
* Requires at least: 3.8
* Tested up to: 4.0
*
* Copyright: © 2014 Manos Psychogyiopoulos ([email protected]).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// To use this snippet, download this file into your plugins directory and activate it, or copy the code under this line into the functions.php file of your (child) theme.
add_filter( 'wcml_cart_contents', 'wpml_composites_compat', 11, 4 );
add_filter( 'wcml_exception_duplicate_products_in_cart', 'wpml_composites_dupicate_exception', 10, 2 );
add_filter( 'woocommerce_composite_component_options_query_args', 'wpml_composites_transients_cache_per_language', 10, 3 );
function wpml_composites_compat( $new_cart_data, $cart_contents, $key, $new_key ) {
global $sitepress;
if ( isset( $cart_contents[ $key ][ 'composite_children' ] ) || isset( $cart_contents[ $key ][ 'composite_parent' ] ) ) {
$buff = $new_cart_data[ $new_key ];
unset( $new_cart_data[ $new_key ] );
$new_cart_data[ $key ] = $buff;
}
return $new_cart_data;
}
function wpml_composites_dupicate_exception( $exclude, $cart_item ) {
if ( isset( $cart_item[ 'composite_parent' ] ) || isset( $cart_item[ 'composite_children' ] ) ) {
$exclude = true;
}
return $exclude;
}
function wpml_composites_transients_cache_per_language( $args, $query_args, $component_data ) {
global $sitepress;
$args[ 'wpml_lang' ] = $sitepress->get_current_language();
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment