0, 'context' => 'archive', 'design' => '', ), is_array( $atts ) ? $atts : array(), self::TAG ); $product = self::resolve_product( (int) $atts['id'] ); if ( ! $product instanceof WC_Product ) { return ''; } if ( ! $product->is_type( 'variable' ) ) { return ''; } if ( ! class_exists( 'AIEO_DMM_Swatches_Runtime' ) ) { return ''; } $context = ( 'single' === $atts['context'] || 'product' === $atts['context'] ) ? 'single' : 'archive'; $design = sanitize_key( (string) $atts['design'] ); $filter = null; if ( in_array( $design, array( 'aieo', 'inherit' ), true ) ) { $filter = static function () use ( $design ) { return $design; }; add_filter( 'aieo_theme_surface_mode', $filter, 99 ); } $html = AIEO_DMM_Swatches_Runtime::instance()->render_card_swatches_html( $product, $context ); if ( $filter ) { remove_filter( 'aieo_theme_surface_mode', $filter, 99 ); } if ( '' === $html ) { return ''; } return '
' . $html . '
'; } private static function resolve_product( $id = 0 ) { if ( ! function_exists( 'wc_get_product' ) ) { return null; } if ( $id > 0 ) { $product = wc_get_product( $id ); return $product instanceof WC_Product ? $product : null; } global $product; if ( $product instanceof WC_Product ) { return $product; } $post_id = (int) get_the_ID(); if ( $post_id > 0 && 'product' === get_post_type( $post_id ) ) { $resolved = wc_get_product( $post_id ); return $resolved instanceof WC_Product ? $resolved : null; } return null; } }