在WooCommerce相关插件中,地址如下: 在此输入链接描述
插件:YITH WooCommerce 附属机构
我想将端点添加到仪表板菜单。
我想将此部分用作广告工具,例如放置横幅。
我将以下行添加到 class-yith-wcaf-endpoints.php 文件中。
'banners' => _x( 'Banners', '[GLOBAL] Endpoint title', 'yith-woocommerce-affiliates' ),
我还再次保存了固定链接设置以修复 404 错误。
这样,横幅项目就被添加到仪表板菜单中了。然后我在templates/shortcodes路径中创建了一个名为dashboard-banners.php的文件,并将以下代码放入其中。
<?php
/**
* Affiliate Banners
*
* @author YITH
* @package YITH\Affiliates\Templates
* @version 2.0.0
*/
/**
* Template variables:
*
* @var $affiliate YITH_WCAF_Affiliate
* @var $generated_url string
* @var $original_url string
* @var $share_enabled bool
* @var $atts array
* @var $share_atts array
*/
if ( ! defined( 'YITH_WCAF' ) ) {
exit;
} // Exit if accessed directly
?>
<?php
do_action( 'yith_wcaf_before_dashboard_section', 'banners', $atts );
?>
<div>
<h1>Welcome to the Banners endpoint!</h1>
</div>
<?php
do_action( 'yith_wcaf_after_dashboard_section', 'banners', $atts );
现在我希望将放入仪表板-banners.php 文件中的自定义内容显示在横幅的端点处。
我感谢任何帮助和指导。
谢谢你
我知道已经有一段时间了,但这对我有用-
add_action('init', function () {
add_rewrite_endpoint('my-coins', EP_PERMALINK);
});
add_action('init', function () {
add_rewrite_rule(
'^my-coins/?$',
'index.php?my-coins=true',
'top'
);
});
add_filter('request', function ($vars) {
if(isset($vars['my-coins'])) {
$vars['my-coins'] = true;
}
return $vars;
});
function load_custom_endpoint_content()
{
if (get_query_var('my-coins')) {
echo 'Hello, World!';
// include get_template_directory() . '/custom-template.php';
exit;
}
}
add_action('template_redirect', 'load_custom_endpoint_content');