我对创建基本填充WooCommerce签出模板部分的短代码感兴趣。例如,在我的子主题的functions.php中:
function shortcode_review_order() {
//get the template part from woocommerce/templates/checkout/review-order.php
wc_get_template_part('checkout/review-order');
}
add_shortcode( 'custom_review_order', 'shortcode_review_order' );...and然后在我的页面..。
<div>[custom_review_order]</div>当我尝试这个的时候,我的结账页面上什么也没有出现。
这有可能吗?
发布于 2017-05-16 01:42:44
你的代码中很少有错误..。
首先,您应该使用init钩子添加一个短代码。
add_action( 'init', 'add_shortcodes' );
function add_shortcodes(){
add_shortcode( 'custom_review_order', 'shortcode_review_order' );
}然后,缺少模板的.php部分。此外,它还需要如下所示的数组参数。使用wc_get_template可以得到更精确的结果。
function shortcode_review_order(){
wc_get_template( 'checkout/review-order.php', array( 'checkout' => WC()->checkout() ) );
}要更多地了解如何正确使用它的模板,请搜索插件上的每个模板。你会看到它是如何被使用的。你可以得到一个提示,你可以如何使用它为自己。
发布于 2019-08-02 07:53:00
我发现wc_get_template会回显模板,因为返回模板的短代码更好。您可以使用:
$string = wc_get_template_html( $template_name, $args, $template_path, $default_path );
它是“类似于wc_get_template,但返回HTML而不是输出。”
https://stackoverflow.com/questions/43991151
复制相似问题