English 中文(简体)
采用“WooCommerce”在“一页”上,向我显示价格。
原标题:Using a WooCommerce hook on category page causes price display to mess up

I am trying to display some fields on the category product list page and the woocommerce_after_shop_loop_item_title hook. My information comes out perfectly, except it causes EACH product to display ALL the prices of the products on that page. If I remove my hook it works right again. I added this:

add_action(  woocommerce_after_shop_loop_item_title ,  paradigm_custom_category_display , 5 );
function paradigm_custom_category_display() {
    global $product;

    if ( $product->get_short_description()) {
        ?>
        <h2 class="woocommerce-loop-product__title pp-shortdescription">
            <?php echo apply_filters(  woocommerce_short_description , $product->get_short_description() ) ?>
        </h2>   
    <?php
    }
    ?>

    <div class="pp-block">
    <?php
    if(get_field( author_name )) {
        ?>
        <div class="pp-author"><span>Author: </span><a href="<?php the_field( author_link ); ?>" class="fancybox-iframe"><?php the_field( author_name ); ?></a></div>
        <?php   
    }
    if(get_field( pages )) {
        ?>
        <div class="pp-pages"><span>Pages: </span><?php the_field( pages ); ?></div>
        <?php   
    }   
    if(get_field( size )) {
        ?>
        <div class="pp-size"><span>Size: </span><?php the_field( size ); ?></div>
        <?php   
    }   
    if(get_field( isbn )) {
        ?>
        <div class="pp-isbn"><span>ISBN: </span><?php the_field( isbn ); ?></div>
        <?php   
    }   
    if(get_field( binding )) {
        ?>
        <div class="pp-binding"><span>Binding: </span><?php the_field( binding ); ?></div>
        <?php   
    }
    ?>
        </div>
    <?php
}

And that works for my new category information display. BUT EACH product shown also shows the price of ALL the products on the page now:

enter image description here

I removed each block of my function and that made no difference. The only way the price goes back to the correct display is not putting in the hook at all. I am new to this and lost. Can anyone help? Thanks.

问题回答

这里的主要问题是,你正在现有链接内容(不允许链接)内显示联系。

You will need to change this line removing the author link:

<div class="pp-author"><span>Author: </span><a href="<?php the_field( author_link ); ?>" class="fancybox-iframe"><?php the_field( author_name ); ?></a></div>

like:

<div class="pp-author"><span>Author: </span><?php the_field( author_name ); ?></div>

www.un.org/Depts/DGACM/index_spanish.htm 还确保产品简短描述显示内容,没有链接。

This should solve this double link issue (but maybe not this pricing strange glitch)


Now you should try to buffer the outputted content, as it can solve some strange issues. I have also restricted the allowed HTML tags in the product short description.

I have revisited your code:

add_action(  woocommerce_after_shop_loop_item_title ,  paradigm_custom_category_display , 4 );
function paradigm_custom_category_display() {
    global $product;

    ob_start(); // start buffering outputted content

    if ( ! empty($product->get_short_description()) ) {
        ?>
        <h2 class="woocommerce-loop-product__title pp-shortdescription">
            <?php // Restricting allowed html tags (no links)
            $args = array(  br  => [],  p  => [],  em  => [],  strong  => [],  span  => [],  div  => [] );
            echo apply_filters(  woocommerce_short_description , wp_kses( $product->get_short_description(), $args ) ) ?>
        </h2>   
    <?php } ?>
    <div class="pp-block">
    <?php
    if( $author_name = get_field( author_name ) ) { ?>
        <div class="pp-author"><span><?php _e( Author: ); ?> </span><?php echo $author_name; ?></div><?php   
    }
    if( $pages = get_field( pages ) ) { ?>
        <div class="pp-pages"><span><?php _e( Pages: ); ?> </span><?php echo $pages; ?></div><?php   
    }   
    if( $size = get_field( size ) ) { ?>
        <div class="pp-size"><span><?php _e( Size: ); ?> </span><?php echo $size; ?></div><?php   
    }   
    if( $isbn = get_field( isbn ) ) {
        ?>
        <div class="pp-isbn"><span><?php _e( ISBN: ); ?> </span><?php echo $isbn; ?></div><?php   
    }   
    if( $binding = get_field( binding ) ) { ?>
        <div class="pp-binding"><span><?php _e( Binding: ); ?> </span><?php echo $binding; ?></div><?php   
    }
    ?></div><?php
    
    echo ob_get_clean(); // Output the buffered content
}

它应当发挥作用。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签