Woocommerce Customs Endpoint

时间:2017-10-25 作者:Dannie Herdyawan

我为添加的自定义端点创建代码段,下面是我的代码:

/**
 * Register new endpoint to use inside My Account page.
 *
 * @see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
 */
function my_subscriptions_endpoints() {
    add_rewrite_endpoint( \'my-subscriptions\', EP_ROOT | EP_PAGES );
}
add_action( \'init\', \'my_subscriptions_endpoints\' );

/**
 * Add new query var.
 *
 * @param array $vars
 * @return array
 */
function my_subscriptions_query_vars( $vars ) {
    $vars[] = \'my-subscriptions\';

    return $vars;
}
add_filter( \'query_vars\', \'my_subscriptions_query_vars\', 0 );


/**
 * Flush rewrite rules on theme activation.
 */
function my_subscriptions_flush_rewrite_rules() {
    add_rewrite_endpoint( \'my-subscriptions\', EP_ROOT | EP_PAGES );
    flush_rewrite_rules();
}
add_action( \'after_switch_theme\', \'my_subscriptions_flush_rewrite_rules\' );

/**
 * Custom help to add new items into an array after a selected item.
 *
 * @param array $items
 * @param array $new_items
 * @param string $after
 * @return array
 */
function my_subscriptions_insert_after_helper( $items, $new_items, $after ) {
    // Search for the item position and +1 since is after the selected item key.
    $position = array_search( $after, array_keys( $items ) ) + 1;

    // Insert the new item.
    $array = array_slice( $items, 0, $position, true );
    $array += $new_items;
    $array += array_slice( $items, $position, count( $items ) - $position, true );

    return $array;
}

/**
 * Insert the new endpoint into the My Account menu.
 *
 * @param array $items
 * @return array
 */
function my_subscriptions_my_account_menu_items( $items ) {
    $new_items = array();
    $new_items[\'my-subscriptions\'] = __( \'My Subscriptions\', \'woocommerce\' );

    // Add the new item after `orders`.
    return my_subscriptions_insert_after_helper( $items, $new_items, \'orders\' );
}
add_filter( \'woocommerce_account_menu_items\', \'my_subscriptions_my_account_menu_items\' );

/**
 * Custom Endpoint content
 */
function gc_custom_endpoint_content() {
    echo do_shortcode(\'[ywsbs_my_account_subscriptions]\');
}
add_action( \'woocommerce_account_my-subscriptions_endpoint\', \'gc_custom_endpoint_content\' );
此代码段显示My Subscriptions 带端点的选项卡my-subscriptions 对于gear图标,我的问题是如何更改图标?

1 个回复
最合适的回答,由SO网友:mmm 整理而成

您可以使用CSS和FontAwesome更改图标http://fontawesome.io/

e、 g.放置日历

.woocommerce-MyAccount-navigation ul li.woocommerce-MyAccount-navigation-link--my-subscriptions a::before
{
    content : "\\f073";
}

结束

相关推荐

Dynamic Endpoints

我在WordPress外部有一个数据库表,需要为其创建端点。我已经创建了一个页面/cars/ 我计划使用页面模板生成链接。我希望url看起来像/cars/camaro/ ()/cars/%model%/ ). 起初,我认为我可以使用端点,但不知道如何根据从模型表中提取的段塞使它们动态。我也不确定使用Permalink结构标签是更容易还是更好。我甚至不完全确定从哪里开始,我以前创建过“静态”端点,所以我有一个基础可以跳出,但当我到达request 我不知道该怎么办。/** * Add endpoi