小编Rem*_*mco的帖子

在 Woocommerce 中不重新加载自定义购物车计数不会更新

我有 ajax 脚本排队,但我似乎无法在不刷新页面的情况下更新购物车项目数。

职能:

// Add scripts and stylesheets
function startwordpress_scripts() {
    wp_enqueue_style( 'reset', get_template_directory_uri() . '/reset.css' );
    wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'style', get_template_directory_uri() . '/veggiee.css');
    wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true);
}

function woocommerce_header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    $fragments['a.cart-customlocation'] = ob_get_clean();
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_validation', 'is_product_the_same_cat', 10, 3 );
Run Code Online (Sandbox Code Playgroud)

HTML:

<ul>
<li>
<a href="/cart" id="cart_icon"></a></li><li><span class="counter"> 
<?php echo sprintf ( _n( '%d', '%d', WC()->cart>get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></span></li>
<li id="access"><?php wp_nav_menu( array( 'sort_column' => …
Run Code Online (Sandbox Code Playgroud)

php ajax wordpress cart woocommerce

3
推荐指数
1
解决办法
6052
查看次数

当错误时,strpos仍然返回

$post_id = 228;

$content_post = get_post($post_id);
$content = $content_post->post_content;


$doc = new DOMDocument();
$doc->loadHTML($content);

$links = $doc->getElementsByTagName('a');

foreach ($links as $link){
    $href = $link->getAttribute('href');
    $avoid  = array('.jpg', '.png', '.gif', '.jpeg');

    if (strpos($href, $avoid) == false) {
        echo $link->nodeValue, '<br>';
        echo $href, '<br>';
    }
}
Run Code Online (Sandbox Code Playgroud)

当错误时,strpos仍然会返回网址 - 任何想法我错过了什么?!==也不起作用.

添加信息:我试图排除所有图片网址,所以如果你有更好的方式 - 随意分享.

更新,也没有做到这一点.(尝试使用文档).

    foreach ($links as $link){
    $href = $link->getAttribute('href');
    $avoid  = array('.jpg', '.png', '.gif', '.jpeg');
    $pos = strpos($href, $avoid);

    if ($pos === false) {

    echo $link->nodeValue, '<br>';
    echo $href, …
Run Code Online (Sandbox Code Playgroud)

php function strpos

0
推荐指数
1
解决办法
46
查看次数

标签 统计

php ×2

ajax ×1

cart ×1

function ×1

strpos ×1

woocommerce ×1

wordpress ×1