Wordpress 当购物车不为空时更新文本

Wordpress 当购物车不为空时更新文本,wordpress,woocommerce,Wordpress,Woocommerce,我在我的Wordpress网站上有一个横幅,我想在Ajax没有清空购物车时更新它 以下是非Ajaxified版本: function dynamic_banner() { $atts = '<div class="woofc-shipping">' . alg_wc_get_left_to_free_shipping('<span style="color:#F79917"><i class="fa

我在我的Wordpress网站上有一个横幅,我想在Ajax没有清空购物车时更新它

以下是非Ajaxified版本:

function dynamic_banner() {
    
    $atts = '<div class="woofc-shipping">' . alg_wc_get_left_to_free_shipping('<span style="color:#F79917"><i class="fas fa-shipping-fast" style="margin-left: 5px;"></i>Add %amount_left_for_free_shipping%  more for Free shipping</span> <div class="woofc-total-right"></div>') . '</div>';
    
    if ( ! WC()->cart->is_empty() ) {
    ?>
    <script>
    jQuery(function($){
    $(".ban-text").replaceWith('<?php echo $atts; ?>')});
    </script>
    <?php   
    }
}
add_action('wp_head', 'dynamic_banner');
函数动态_banner(){
$atts=''.alg_wc_get_left_to_free_shipping('Add%amount_left_for_free_shipping%more for free shipping');
如果(!WC()->购物车->为空(){
?>
jQuery(函数($){
$(“.ban text”).replace为(“”)};

感谢您的帮助,我们找到了解决方案

Functions.php代码:

// Shortcode for the banner 
function display_free_shipping_progress() {
    return get_free_shipping_progress();
}
add_shortcode('fs_progress', 'display_free_shipping_progress');

// Function that makes calculations and display
function get_free_shipping_progress() {
    $atts = '<div class="woofc-shipping">' . alg_wc_get_left_to_free_shipping('<span style="color:#F79917"><i class="fas fa-shipping-fast" style="margin-left: 5px;"></i>הוסיפי עוד %amount_left_for_free_shipping% למשלוח חינם</span> <div class="woofc-total-right"></div>') . '</div>';

    $prodgress = WC()->cart->total;

    //Check if cart has something else show default
    if( $prodgress > 0 ) {
        return '<div class="head_strip over--hide" style="display: block;">' . $atts . '</div>';
    } else {
        return '<div class="head_strip over--hide" style="display: block;"><span class="ban-text"><strong>*משלוח מהיר חינם</strong > בקניה מעל<span class="special-price">295₪</span> גם בתקופת הסגר!</span></div>';
    }
}

// Refreshing "free shipping" progress on cart ajax events
add_filter( 'woocommerce_add_to_cart_fragments', 'refresh_free_shipping_progress' );
function refresh_free_shipping_progress( $fragments ){
    $fragments['.head_strip'] = get_free_shipping_progress();

    return $fragments;
}
//横幅的短代码
功能显示\免费\发货\进度(){
return get_free_shipping_progress();
}
添加快捷码(“fs\U进度”、“显示免费配送进度”);
//进行计算和显示的函数
函数get_free_shipping_progress(){
$atts=''.alg_wc_get_left_to_free_shipping('1492;סעפעיעדu left_for_free_shipping%㪚שץננםץםםץםםץץ;
$prodgress=WC()->购物车->总计;
//检查购物车是否有其他显示默认值的内容
如果($prodgress>0){
返回“.$atts.”;
}否则{
返回;
}
}
//刷新购物车ajax事件的“免费送货”进度
添加过滤器('woocommerce'u add'u to'u cart'u fragments','refresh'u free'u shipping'u progress');
函数刷新\免费\发货\进度($fragments){
$fragments['.head_strip']=获取免费配送进度();
返回$fragments;
}

已通过所有简化编码所需的HTML,如推荐的。

您的问题中需要HTML生成的输出,或与
相关的原始HTML。ban text
选择器…要了解如何在购物车更改时刷新,请参阅抱歉,已编辑并添加。下次,请尝试翻译StackOverFlow是一个英文网站。我在你的提供生成的html中没有看到任何带有选择器的标记
class=“ban text”
嘿,朋友,我正在查看你以前的答案,我得到了一个解决方案!非常感谢。很好,你找到了+1的方法
// Shortcode for the banner 
function display_free_shipping_progress() {
    return get_free_shipping_progress();
}
add_shortcode('fs_progress', 'display_free_shipping_progress');

// Function that makes calculations and display
function get_free_shipping_progress() {
    $atts = '<div class="woofc-shipping">' . alg_wc_get_left_to_free_shipping('<span style="color:#F79917"><i class="fas fa-shipping-fast" style="margin-left: 5px;"></i>הוסיפי עוד %amount_left_for_free_shipping% למשלוח חינם</span> <div class="woofc-total-right"></div>') . '</div>';

    $prodgress = WC()->cart->total;

    //Check if cart has something else show default
    if( $prodgress > 0 ) {
        return '<div class="head_strip over--hide" style="display: block;">' . $atts . '</div>';
    } else {
        return '<div class="head_strip over--hide" style="display: block;"><span class="ban-text"><strong>*משלוח מהיר חינם</strong > בקניה מעל<span class="special-price">295₪</span> גם בתקופת הסגר!</span></div>';
    }
}

// Refreshing "free shipping" progress on cart ajax events
add_filter( 'woocommerce_add_to_cart_fragments', 'refresh_free_shipping_progress' );
function refresh_free_shipping_progress( $fragments ){
    $fragments['.head_strip'] = get_free_shipping_progress();

    return $fragments;
}