Javascript代码适用于小提琴但不适用于Wordpress(woocommerce)

时间:2016-06-15 18:15:51

标签: javascript jquery wordpress woocommerce

我在计算正常价格后添加了总价格 - 销售价格并在那里添加了Javascript代码,这应该隐藏总价格为0.它在小提琴中起作用但在wordpress中不起作用。也许我把它放在错误的地方(content-product.php)

我的小提琴就在这里:https://jsfiddle.net/foduxc0y/

wordpress中的代码:

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
<script>
jQuery( document ).ready(function($) {
    "use strict";
    if (parseInt($(".win").text(), 10) === 0) {
        $(".hinnavoit").hide();
        $(".jah").hide();
    }
});
  </script>
</head>
</html>

<?php
/**
 * The template for displaying product content within loops.
 *
 * Override this template by copying it to yourtheme/woocommerce/content-product.php
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.4.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $product, $woocommerce_loop;

// Store loop count we're currently on
if ( empty( $woocommerce_loop['loop'] ) ) {
    $woocommerce_loop['loop'] = 0;
}

// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) ) {
    $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
}

// Ensure visibility
if ( ! $product || ! $product->is_visible() ) {
    return;
}

// Increase loop count
$woocommerce_loop['loop']++;

// Extra post classes
$classes = array();
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] ) {
    $classes[] = 'first';
}
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) {
    $classes[] = 'last';
}
?>
<li <?php post_class( $classes ); ?>>

    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

    <figure class="item effect-bubba">
        <?php
            /**
             * woocommerce_before_shop_loop_item_title hook
             *
             * @hooked woocommerce_show_product_loop_sale_flash - 10
             * @hooked woocommerce_template_loop_product_thumbnail - 10
             */
            do_action( 'woocommerce_before_shop_loop_item_title' );
        ?>


            <figcaption>


                <div class="hover_icons" onclick="location.href='<?php the_permalink(); ?>';">
            <i class="fa fa-file-text-o"></i> </br>
            Uuri lähemalt
        </div>


                </figcaption>


        </figure>

        <div class="item_det">

            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

            <?php
                /**
                 * woocommerce_after_shop_loop_item_title hook
                 *
                 * @hooked woocommerce_template_loop_rating - 5
                 * @hooked woocommerce_template_loop_price - 10
                 */
                do_action( 'woocommerce_after_shop_loop_item_title' );
            ?>

<p>
<span class="jah">
<span> Sinu võit:
<span class="win">
    <span class="hinnavoit"><?php echo $product->get_regular_price()-$product->get_sale_price();?></span>€
</span>
</span>
</span>
</p>

<?php do_action( 'woocommerce_after_shop_loop_item' );?>

        </div>
</li>

0 个答案:

没有答案