如何在产品列表/循环中的每个产品下方显示表格

时间:2020-03-06 作者:Nguyễn Ngọc Anh

enter image description here

我想知道在Wordpress WooCommerce中,如何在每个产品下面显示这样一个表。有人知道这方面的插件或脚本吗?我正在使用XStore主题

编辑:我有一个插件级定价表。它仅在产品页面中显示定价表,而不在循环中显示。我想知道如何使其显示在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>\' ;
        }

    }

1 个回复
SO网友:Adam

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:

相关推荐