简短代码的店面产品模板不受挂钩影响

问题描述

当我使用钩子向产品归档模板添加一些html时,这将产生可见的结果。例如,此挂钩在Woocommerce类别页面上可以很好地发挥作用:

add_action( 'woocommerce_after_shop_loop_item_title',function(){
    global $product;
    $brand = get_field('brand');
    $stock = wc_get_product_stock_quantity();
    $low_stock = $product->get_low_stock_amount();

    echo $product->get_price();
    if($stock > $low_stock){ // Plenty stock
        echo 'in stock';
    }
    else if($stock >0){ // Low stock
        echo 'low stock';
    }
    else{ // No stock
        echo 'no stock';
    }
    echo '<div class = "loop-btn-view-product button">View product</div>';
    echo '<span class = "clear"></span>';
},9 );

但是,我搜索了几个小时,为什么在认的Storefront Gutenberg产品块中看不到此模板更改,这些认产品块显示首页上最受欢迎的产品。

主题/storefront/woocommerce/storefront-woocommerce-template-functions.PHP中,我发现了这一点:

function storefront_best_selling_products( $args ) {
        $args = apply_filters(
            'storefront_best_selling_products_args',array(
                'limit'   => 4,'columns' => 4,'orderby' => 'popularity','order'   => 'desc','title'   => esc_attr__( 'Best Sellers','storefront' ),)
        );

        $shortcode_content = storefront_do_shortcode(
            'products',apply_filters(
                'storefront_best_selling_products_shortcode_args',array(
                    'per_page' => intval( $args['limit'] ),'columns'  => intval( $args['columns'] ),'orderby'  => esc_attr( $args['orderby'] ),'order'    => esc_attr( $args['order'] ),)
            )
        );

        /**
         * Only display the section if the shortcode returns products
         */
        if ( false !== strpos( $shortcode_content,'product' ) ) {
            echo '<section class="storefront-product-section storefront-best-selling-products" aria-label="' . esc_attr__( 'Best Selling Products','storefront' ) . '">';

            do_action( 'storefront_homepage_before_best_selling_products' );

            echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';

            do_action( 'storefront_homepage_after_best_selling_products_title' );

            echo $shortcode_content; // WPCS: XSS ok.

            do_action( 'storefront_homepage_after_best_selling_products' );

            echo '</section>';
        }
    }

因此,似乎该模板是由称为“产品”的短代码生成的。但是我该如何编辑它,为什么它已经不受钩子影响了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)