如何在YITH WooCommerce Affiliates自定义端点显示自定义内容
你已经完成了端点注册与模板文件创建,只需补充以下步骤,即可让自定义模板内容在Banners端点页面正常显示:
1. 添加端点渲染回调逻辑
YITH WooCommerce Affiliates的仪表盘端点依赖专属钩子来绑定内容渲染逻辑。在主题的functions.php文件或自定义插件中添加以下代码,关联banners端点与你的模板:
add_action( 'yith_wcaf_dashboard_section_banners', 'render_banners_dashboard_section' ); function render_banners_dashboard_section( $atts ) { // 获取目标模板路径 $template = YITH_WCAF()->get_template_path( 'shortcodes/dashboard-banners.php' ); // 准备模板所需的变量数据 $affiliate = YITH_WCAF_Affiliates()->get_current_affiliate(); $generated_url = YITH_WCAF()->get_affiliate_url( get_permalink( wc_get_page_id( 'shop' ) ), $affiliate->get_id() ); $original_url = get_permalink( wc_get_page_id( 'shop' ) ); $share_enabled = YITH_WCAF()->get_option( 'enable_share' ); $share_atts = array(); // 加载模板并传递变量 wc_get_template( $template, array( 'affiliate' => $affiliate, 'generated_url' => $generated_url, 'original_url' => $original_url, 'share_enabled' => $share_enabled, 'atts' => $atts, 'share_atts' => $share_atts, ), '', YITH_WCAF()->get_templates_dir() ); }
2. 确认模板路径正确性
- 若直接修改插件文件,确保
dashboard-banners.php存放在插件目录的templates/shortcodes/下; - 推荐用子主题重写模板:将模板文件放在主题目录的
yith-woocommerce-affiliates/shortcodes/下,避免插件更新丢失修改。
3. 刷新固定链接并测试
进入WordPress后台「设置→固定链接」页面,直接点击「保存更改」刷新规则,之后访问联盟仪表盘的Banners端点,即可看到模板中的自定义内容。
内容的提问来源于stack exchange,提问作者matin
相关产品推荐
相关产品推荐

