Javascript 在woocommerce中,当鼠标移动到购物车图标时,如何创建幻灯片来显示产品?
在woocommerce中,当鼠标移动到购物车图标时,如何创建幻灯片来显示产品? 就像下面的截图 这是my header.php脚本Javascript 在woocommerce中,当鼠标移动到购物车图标时,如何创建幻灯片来显示产品?,javascript,php,css,wordpress,woocommerce,Javascript,Php,Css,Wordpress,Woocommerce,在woocommerce中,当鼠标移动到购物车图标时,如何创建幻灯片来显示产品? 就像下面的截图 这是my header.php脚本 <?php /** * The header for our theme. * * This is the template that displays all of the <head> section and everything up until <div id="content"> * * @link https:
<?php
/**
* The header for our theme.
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package themetest
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'gg' ); ?></a>
<header id="masthead" class="site-header" role="banner">
<nav id="site-navigation" class="main-navigation2" role="navigation">
<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false"><?php esc_html_e( 'Top Menu', 'gg' ); ?></button>
<?php
global $woocommerce;
// get cart quantity
$qty = $woocommerce->cart->get_cart_contents_count();
// get cart total
$total = $woocommerce->cart->get_cart_total();
// get cart url
$cart_url = $woocommerce->cart->get_cart_url();
// if multiple products in cart
if($qty>1)
echo '<ul class="menu nav-menu"><li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-27"><a href="'.$cart_url.'">'.$qty.' <i class="cart_control">::before</i></a></li> </ul>';
// if single product in cart
if($qty==1)
echo '<a href="'.$cart_url.'">1 product | '.$total.'</a>';
?>
<?php wp_nav_menu( array( 'theme_location' => 'top', 'menu_id' => 'top-menu' ) ); ?>
</nav><!-- #site-navigation -->
<div class="site-branding">
<?php if ( is_front_page() && is_home() ) : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<?php else : ?>
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
<?php endif; ?>
<p class="site-description"><?php bloginfo( 'description' ); ?></p>
</div><!-- .site-branding -->
<nav id="site-navigation" class="main-navigation" role="navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'gg' ); ?></button>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu' ) ); ?>
</nav><!-- #site-navigation -->
</header><!-- #masthead -->
<div id="content" class="site-content">
或者你也可以像我上面说的那样查看更多信息。
我正在使用最新的woocommerce插件。在这里更改
首先更改代码
if($qty==1)
echo '<ul class='mini-cart'><li><a href="'.$cart_url.'">1 product | '.$total.'</a><div class="cart-Items">' woocommerce_mini_cart() '</div> <li></ul>';
这不是完整的设计,但您将获得微型购物车并将其悬停显示。能否在其中添加html而不是PHP脚本。。所以,了解一下你的导航结构吧。请再检查一遍!您的代码有语法错误并已修复,但给出如下错误结果:
if($qty==1)
echo '<ul class='mini-cart'><li><a href="'.$cart_url.'">1 product | '.$total.'</a><div class="cart-Items">' woocommerce_mini_cart() '</div> <li></ul>';
.mini-cart li {
position:relative;
}
.mini-cart li ul{
position:absolute;
display:none;
}
.mini-cart li:hover ul{
display:block;
}