woocommerce offtopic - How to display a table below each product in product listloop

I wanted to know how to display a table under each product like this in Wordpress WooCommerce. Does anyone know any plug

I wanted to know how to display a table under each product like this in Wordpress WooCommerce. Does anyone know any plugins or scripts for this? I'm using XStore theme

Edit: I have a plugin caled tier pricing table. It only display the pricing table in product page, not in the loop. I want to know how to make it display on product loop:

if ( $product ) {

        if ( $product->is_type( 'simple' ) ) {
            $this->renderPricingTable( $product->get_id() );
        } elseif ( $product->is_type( 'variable' ) ) {
            echo  '<div data-variation-price-rules-table></div>' ;
        }

    }

I wanted to know how to display a table under each product like this in Wordpress WooCommerce. Does anyone know any plugins or scripts for this? I'm using XStore theme

Edit: I have a plugin caled tier pricing table. It only display the pricing table in product page, not in the loop. I want to know how to make it display on product loop:

if ( $product ) {

        if ( $product->is_type( 'simple' ) ) {
            $this->renderPricingTable( $product->get_id() );
        } elseif ( $product->is_type( 'variable' ) ) {
            echo  '<div data-variation-price-rules-table></div>' ;
        }

    }
Share Improve this question edited Mar 10, 2020 at 3:30 Nguyễn Ngọc Anh asked Mar 6, 2020 at 15:43 Nguyễn Ngọc AnhNguyễn Ngọc Anh 93 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The shop archive or in general any product-loop that passes through:

woocommerce/templates/archive-product.php

...or utilizes similar logic found in that template, by calling:

wc_get_template_part( 'content', 'product' );

which retrieves the following template:

woocommerce/templates/content-product.php

...will then make available the following actions:

Excerpt from: woocommerce/templates/content-product.php (version 3.6.0 at the time of this answer)

    /**
     * Hook: woocommerce_before_shop_loop_item.
     *
     * @hooked woocommerce_template_loop_product_link_open - 10
     */
    do_action( 'woocommerce_before_shop_loop_item' );

    /**
     * Hook: woocommerce_before_shop_loop_item_title.
     *
     * @hooked woocommerce_show_product_loop_sale_flash - 10
     * @hooked woocommerce_template_loop_product_thumbnail - 10
     */
    do_action( 'woocommerce_before_shop_loop_item_title' );

    /**
     * Hook: woocommerce_shop_loop_item_title.
     *
     * @hooked woocommerce_template_loop_product_title - 10
     */
    do_action( 'woocommerce_shop_loop_item_title' );

    /**
     * Hook: woocommerce_after_shop_loop_item_title.
     *
     * @hooked woocommerce_template_loop_rating - 5
     * @hooked woocommerce_template_loop_price - 10
     */
    do_action( 'woocommerce_after_shop_loop_item_title' );

    /**
     * Hook: woocommerce_after_shop_loop_item.
     *
     * @hooked woocommerce_template_loop_product_link_close - 5
     * @hooked woocommerce_template_loop_add_to_cart - 10
     */
    do_action( 'woocommerce_after_shop_loop_item' );

The hook you probably want is:

do_action( 'woocommerce_after_shop_loop_item' );

Therefore add the following to your theme functions.php file or wherever your business logic is:

function wpse_360157_after_shop_loop_item() {

  // add your logic here to print after the add-to-cart button, example:

  // echo '<table>...</table>';

  // OR...

  // include_once( 'path/to/product-loop-table.php' );

  // OR...

  // get_template_part( 'product-loop-table.php' );

  // Etc..

}

add_action( 'woocommerce_after_shop_loop_item' 'wpse_360157_after_shop_loop_item' );

Useful reading:

  • https://docs.woocommerce/document/template-structure/
  • https://github/woocommerce/woocommerce/blob/master/templates/content-product.php
  • https://developer.wordpress/reference/functions/get_template_part/
  • How to use get_template_part()?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744682953a4587742.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信