Сайт работает на Divi + WooCommerce. Мне нужно переделать обычный значок корзины в мини-корзину с выпадающим списком. Готовые решения не подходили, поэтому пришлось самому себе. Существует 100% рабочий код, который я пытаюсь вызвать через короткий код. Проблема в том, что код запускается и обычно работает, но «вылетает» за пределы всех div-ов.
if ( ! function_exists( 'puhelinfix_header_cart' ) ) {
function puhelinfix_header_cart() {
$class = 'current-menu-item';
?>
<ul id="site-header-cart" class="site-header-cart menu">
<li class="<?php echo esc_attr( $class ); ?>">
<?php puhelinfix_cart_link(); ?>
</li>
<li>
<?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
</li>
</ul>
<?php
}
}
add_shortcode('divi-mini-cart', 'puhelinfix_header_cart');
if ( ! function_exists( 'puhelinfix_cart_link' ) ) {
function puhelinfix_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'puhelinfix' ); ?>">
<?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'puhelinfix' ), WC()->cart->get_cart_contents_count() ) ); ?></span>
</a>
<?php
if ( ! function_exists( 'puhelinfix_cart_link_fragment' ) ) {
function puhelinfix_cart_link_fragment( $fragments ) {
global $woocommerce;
ob_start();
puhelinfix_cart_link();
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
}
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
add_filter( 'woocommerce_add_to_cart_fragments', 'puhelinfix_cart_link_fragment' );
} else {
add_filter( 'add_to_cart_fragments', 'puhelinfix_cart_link_fragment' );
}
Стрелка указывает, где добавлен шорткод и где он «вылетает»: https://i.stack.imgur.com/avBpW.jpg
В чем может быть проблема?