Wordpress shortcode中的店面产品模板不受hook更改的影响
当我用一个钩子将一些html添加到产品归档模板中时,会得到一个可见的结果。例如,此钩子在Woocommerce类别页面上的作用很好:Wordpress shortcode中的店面产品模板不受hook更改的影响,wordpress,wordpress-theming,wordpress-gutenberg,gutenberg-blocks,wordpress-shortcode,Wordpress,Wordpress Theming,Wordpress Gutenberg,Gutenberg Blocks,Wordpress Shortcode,当我用一个钩子将一些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 =
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 );
add_action('woocommerce_后面的_shop_loop_item_title',函数(){
全球$产品;
$brand=get_字段(“品牌”);
$stock=wc_get_product_stock_quantity();
$low_stock=$product->get_low_stock_amount();
echo$product->get_price();
如果($stock>$low_stock){//充足的stock
echo“库存中”;
}
如果($stock>0){//低库存
回声“低库存”;
}
否则{//没有存货
回声“没有股票”;
}
echo“查看产品”;
回声';
}, 9 );
然而,我已经搜索了几个小时,为什么在默认的Storefront Gutenberg products块中看不到这个模板更改,这些块在主页上显示了最流行的产品
在themes/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>';
}
}
功能店面\u最畅销的\u产品($args){
$args=应用过滤器(
“店面\最畅销\产品\参数”,数组(
“限制”=>4,
“列”=>4,
'orderby'=>'popularity',
“订单”=>“描述”,
“title”=>esc_attr_uuuuuuuuuuuuuu(‘畅销书’、‘店面’),
)
);
$shortcode\u content=storefront\u do\u shortcode(
“产品”,应用过滤器(
“店面\最畅销\产品\快捷码\参数”,数组(
“每页”=>intval($args['limit']),
'columns'=>intval($args['columns']),
'orderby'=>esc_attr($args['orderby']),
“订单”=>esc_attr($args['order']),
)
)
);
/**
*仅当快捷码返回产品时才显示节
*/
if(false!==strpos($shortcode_content,'product')){
回声';
采取行动(“店面、主页、最畅销产品之前”);
回显“.wp_kses_post($args['title'])”;
行动(“店面、主页、最畅销产品、标题”之后);
echo$shortcode_content;//WPCS:XSS正常。
采取行动(“店面、主页、最畅销产品之后”);
回声';
}
}
因此,模板似乎是由一个名为“products”的短代码生成的。但是我如何编辑它,为什么它还没有受到钩子的影响呢