Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Created December 11, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/f87027fd41fee7b2ef9f78f3cd85cf96 to your computer and use it in GitHub Desktop.
Save helgatheviking/f87027fd41fee7b2ef9f78f3cd85cf96 to your computer and use it in GitHub Desktop.
Reduce Mix and Match variation names to only their attributes
<?php
/**
* Plugin Name: WooCommerce Mix and Match Products - Simplify variation names
* Plugin URI: https://woocommerce.com/products/woocommerce-mix-and-match-products
* Description: Reduce container variation names to only their attributes
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com
* Requires at least: 5.5
* Requires PHP: 7.0
* WC requires at least: 4.7.0
* WC tested up to: 4.7.0
*
*/
defined( 'ABSPATH' ) || exit;
class WC_MNM_Simplify_Variation_Names {
/**
* Fire in the hole!
*/
public static function init() {
// Check dependencies.
if ( ! function_exists( 'WC_Mix_and_Match' ) ) {
return false;
}
add_filter( 'woocommerce_cart_item_name', array( __CLASS__, 'cart_variation_name_filter' ), 10, 2 );
add_filter( 'woocommerce_order_item_name', array( __CLASS__, 'variation_name_in_order_table_item_title' ), 10, 2 );
}
/**
* MNM child cart name modification for variations.
*
* @param string $content
* @param array $cart_item
* @return string
*/
public static function cart_variation_name_filter( $content, $cart_item ) {
if ( wc_mnm_maybe_is_child_order_item( $cart_item ) && $cart_item['variation_id'] ) {
$content = wc_get_formatted_variation( $cart_item['data'], true, false );
}
return $content;
}
/**
* MNM child order name modification for variations.
*
* @param string $content
* @param object $order_item
* @return string
*/
public static function variation_name_in_order_table_item_title( $content, $order_item ) {
if ( wc_mnm_is_child_order_item( $order_item ) && $order_item->get_variation_id() ) {
$content = wc_get_formatted_variation( $order_item->get_product(), true, false );
}
return $content;
}
}
add_action( 'plugins_loaded', array( 'WC_MNM_Simplify_Variation_Names', 'init' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment