WooCommerce加入购物车Ajax无法正常工作

时间:2017-02-04 15:26:01

标签: javascript php jquery ajax wordpress

在我目前的自定义主题WooCommerce中,所有标准功能都无法使用Ajax。我做了一些研究,如果我没有弄错的话,这应该是默认行为。我遵循了WooCommerce集成指南,但不确定它为什么不起作用。

不确定发生了什么。即使我删除了functions.php中的自定义选项,也没有执行Ajax调用。我的控制台没有错误。似乎css类就像 ajax_add_to_cart 那样,但没有执行像woocommerce的.js文件那样不存在。

我正在WooCommerce的默认创建页面中进行测试,名为购物

任何帮助都将不胜感激。

woocommerce.php :这是默认的woocommerce(page.php副本)

<?php get_header(); ?>

<?php woocommerce_content(); ?>

<?php get_footer(); ?>

functions.php 在主题中添加了以下自定义功能

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );

add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);

add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_single_add_to_cart_text' );

function woo_custom_single_add_to_cart_text() {

    return __( 'Voeg Toe', 'woocommerce' );

}

function my_theme_wrapper_start() {
    echo '<section id="main">';
}

function my_theme_wrapper_end() {
    echo '</section>';
}

add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

我的HTML添加到购物车按钮代码如下所示:

<a rel="nofollow" 
   href="/theme/shop/?add-to-cart=508" 
   data-quantity="1" data-product_id="508" 
   data-product_sku="" 
   class="button product_type_simple add_to_cart_button ajax_add_to_cart">
   Add to Cart
</a>

在header.php中也有这个 不确定这是否会搞乱WooCommerce功能

<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/jquery.min.js"></script>

0 个答案:

没有答案
相关问题