Reduce Mix and Match variation names to only their attributes
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: 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