【发布时间】:2018-11-02 15:52:09
【问题描述】:
我正在尝试根据用户在 Woocommerce 中的总购买量在我的自定义帐户菜单元素中显示自定义通知,基于此答案代码:
Custom cart notice based on user total purchased amount in Woocommerce
它不像我想的那样工作。我做错了什么?
这是我使用的代码:
add_filter ( 'woocommerce_account_menu_items', 'xu', 40 );
function xu( $menu_links ){
$menu_links = array_slice( $menu_links, 0,3 , true )
+ array( 'xu' => 'Xu của bạn' )
+ array_slice( $menu_links, 3, NULL, true );
return $menu_links;
}
add_action( 'init', 'add_endpoint' );
function add_endpoint() {
add_rewrite_endpoint( 'xu', EP_PAGES );
}
add_action( 'woocommerce_account_xu_endpoint', 'xuxu' );
function xuxu() {
if( ! WC()->session->get( 'purchases_sum' ) ){
WC()->session->set('purchases_sum',
get_customer_total_purchases_sum());
}
$total_purchases = WC()->session->get( 'purchases_sum' );
if ( $total_purchases == 0 ) return; // We exit (no purchases or non logged users)
if ( ( 10000 - $total_purchases ) > 0 )
{
echo 'You need an extra ' . wc_price( 10000 - $total_purchases ) . ' at all to get a... ';
}
else
{
echo '... ';
}
}
感谢任何帮助。
【问题讨论】:
标签: php wordpress woocommerce account items