Created
July 10, 2024 11:03
-
-
Save ibrahim-kardi/0dcb541a129841a242714287d72439e6 to your computer and use it in GitHub Desktop.
woocommerce_account_menu_items add custom menu item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check if the user has purchased specific product IDs | |
function user_has_purchased_product($user_id, $product_ids) { | |
// Get all orders for the user | |
$customer_orders = wc_get_orders(array( | |
'customer_id' => $user_id, | |
'status' => array('completed', 'processing', 'on-hold') | |
)); | |
// Loop through orders and check if the product is purchased | |
foreach ($customer_orders as $order) { | |
foreach ($order->get_items() as $item) { | |
if (in_array($item->get_product_id(), $product_ids)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
// // Add the custom menu item to the My Account navigation | |
function custom_add_my_account_menu_item($items) { | |
// Get current user ID | |
$user_id = get_current_user_id(); | |
// Define the product IDs | |
$product_ids = array(1453, 1454); | |
// Check if the user has purchased any of the specified products | |
if (user_has_purchased_product($user_id, $product_ids)) { | |
$items_array = array_slice($items, 0, 2, true) + | |
array('telegram-signal' => __('Telegram Signal', 'text-domain')) + | |
array_slice($items, 2, null, true); | |
$items = $items_array; | |
//$custom_item = ; | |
//$items = $custom_item + $items; | |
} | |
return $items; | |
} | |
add_filter('woocommerce_account_menu_items', 'custom_add_my_account_menu_item'); | |
// Register the custom endpoint | |
function custom_add_my_account_endpoint() { | |
add_rewrite_endpoint('telegram-signal', EP_ROOT | EP_PAGES); | |
} | |
add_action('init', 'custom_add_my_account_endpoint'); | |
// Display content for the custom endpoint | |
function custom_my_account_endpoint_content() { | |
echo '<p>' . __('Join our Telegram VIP signal group to access all our daily VIP trading signals. You will also receive Tradingview signal alerts for most of our indicators, even if you are using a free Tradingview account.', 'text-domain') . '</p>'; | |
echo '<a href="https://t.me/+ErPBAViqhHEyNTA0" class="telg-btn">' . __('JOINE OUR TELEGRAM SIGNAL', 'text-domain') . '</a>'; | |
} | |
add_action('woocommerce_account_telegram-signal_endpoint', 'custom_my_account_endpoint_content'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment