Поддержка WooCommerce Почему add_to_cart_url является ссылкой на страницу товара?

  • Добрый день.
    В файле add_to_cart.php добавил следующий код

    global $product;
    
    $benefis_attr_str = $product->get_attribute('type_custom');
    
    $benefis_attr_arr = explode(', ', $benefis_attr_str);
    $benefis_attr_arr = array_reverse($benefis_attr_arr);
    $benefis_first_attr = $benefis_attr_arr[0];
    $benefis_second_attr = $benefis_attr_arr[1];
    
    if (!empty($benefis_first_attr && !empty($benefis_second_attr))) {
    $benefis_attr_str = $benefis_first_attr . ' - ' . $benefis_second_attr . ':';
    } elseif (!empty($benefis_first_attr)) {
    $benefis_attr_str = $benefis_first_attr;
    } elseif (empty($benefis_second_attr)) {
    $benefis_attr_str = $benefis_second_attr;
    } else {
    $benefis_attr_str = '';
    }
    
    echo apply_filters('woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
    sprintf('
    	<div class="price-box">
    		<span class="new-price">
    			<span class="price">' . $benefis_attr_str . '<br>
    				' . $product->get_price_html() . '
    			</span>
    		</span>
    	</div>
    </div>
    <div class="product-content2">
    	<h2 class="product-name">
    		<a href="' . get_permalink() . '">' . get_the_title() . '</a>
    	</h2>
    
    	<div class="price-box">
    		<span class="new-price">
    			<span class="price">' . $benefis_attr_str . '<br>
    				' . $product->get_price_html() . '
    			</span>
    		</span>
    	</div>
    	<div class="button-container">
    		<a title="В корзину" href="%s" class="button cart_button %s">
    			<span>' . esc_html__('Read more', 'benefis') . '</span>
    		</a>
    	</div>
    </div>
    ', esc_url($product->add_to_cart_url()), //		esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
    	esc_attr(isset($args['class']) ? $args['class'] : 'button'),
    	isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
    	esc_html($product->add_to_cart_text())), $product, $args);
    
    

    Все правильно отображается, вот только add_to_cart_url выводит ссылку на страницу поста, но не добавляет товар в корзину.

    Уже несколько часов мучаюсь.

    Вот код со страницы content-product.php

    	global $product;
    
    	// Ensure visibility.
    	if (empty($product) || !$product->is_visible()) {
    		return;
    	}
    ?>
    
    <?php //do_action('woocommerce_before_shop_loop_item'); ?>
    
    <div class="product-loop">
        <div class="single-product">
            <?php do_action('woocommerce_before_shop_loop_item'); ?>
    <!--        --><?php //do_action('woocommerce_before_shop_loop_item_title'); ?>
            <?php do_action('woocommerce_shop_loop_item_title'); ?>
    <!--        --><?php //do_action('woocommerce_after_shop_loop_item_title'); ?>
            <?php do_action('woocommerce_after_shop_loop_item'); ?>
        </div>
    </div>
    
    

    Буду признателен за помощь или подсказку.

    Страница, с которой нужна помощь: [войдите, чтобы увидеть ссылку]

  • Тема «Почему add_to_cart_url является ссылкой на страницу товара?» закрыта для новых ответов.