MoeCloudy Posted February 3, 2020 Share Posted February 3, 2020 Hello The code shown below creates a new endpoint to the "my-account" section on my wordpress website. basically it displays the products a user purchased from our site. I just want to EXCLUDE a certain product category to be shown in this endpoint ! i hope you can help me achieve this ! function bbloomer_add_premium_support_endpoint() { add_rewrite_endpoint( 'premium-support', EP_ROOT | EP_PAGES ); } add_action( 'init', 'bbloomer_add_premium_support_endpoint' ); // ------------------ // 2. Add new query var function bbloomer_premium_support_query_vars( $vars ) { $vars[] = 'premium-support'; return $vars; } add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 ); // ------------------ // 3. Insert the new endpoint into the My Account menu function bbloomer_add_premium_support_link_my_account( $items ) { $items['premium-support'] = 'My Products'; return $items; } add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' ); // ------------------ // 4. Add content to the new endpoint function bbloomer_premium_support_content() { echo '<h1>MY PRODUCTS</h1> '; echo do_shortcode( ' [my_purchased_products] ' ); } add_action( 'woocommerce_account_premium-support_endpoint', 'bbloomer_premium_support_content' ); // Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/ Share on other sites More sharing options...
requinix Posted February 3, 2020 Share Posted February 3, 2020 The change you need to make isn't in there. Where is my_purchased_products handled? Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/#findComment-1573982 Share on other sites More sharing options...
MoeCloudy Posted February 4, 2020 Author Share Posted February 4, 2020 SORRY !! i forgot the main code add_shortcode( 'my_purchased_products', 'bbloomer_products_bought_by_curr_user' ); function bbloomer_products_bought_by_curr_user() { // GET CURR USER $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) return; // GET USER ORDERS (COMPLETED + PROCESSING) $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $current_user->ID, 'post_type' => wc_get_order_types(), 'post_status' => array_keys( wc_get_is_paid_statuses() ), ) ); // LOOP THROUGH ORDERS AND GET PRODUCT IDS if ( ! $customer_orders ) return; $product_ids = array(); foreach ( $customer_orders as $customer_order ) { $order = wc_get_order( $customer_order->ID ); $items = $order->get_items(); foreach ( $items as $item ) { $product_id = $item->get_product_id(); $product_ids[] = $product_id; } } $product_ids = array_unique( $product_ids ); $product_ids_str = implode( ",", $product_ids ); // PASS PRODUCT IDS TO PRODUCTS SHORTCODE return do_shortcode("[products ids='$product_ids_str']"); } Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/#findComment-1573983 Share on other sites More sharing options...
requinix Posted February 4, 2020 Share Posted February 4, 2020 If you need to post more code, please use the Code <> dialog to do it. Much easier to read that way. Seems you would handle the product category in foreach ( $items as $item ) { $product_id = $item->get_product_id(); $product_ids[] = $product_id; } there. Like foreach ( $items as $item ) { if (/* the product category is good to show */) { $product_id = $item->get_product_id(); $product_ids[] = $product_id; } } How you go about deciding whether to show, I can't tell. Do you know what method(s) you need to call on $item? Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/#findComment-1573986 Share on other sites More sharing options...
MoeCloudy Posted February 4, 2020 Author Share Posted February 4, 2020 Sorry again, i am new to this forum and to PHP the product category we want to exclude is " courses " so can you write the code with this exclusion ? Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/#findComment-1573987 Share on other sites More sharing options...
requinix Posted February 4, 2020 Share Posted February 4, 2020 No, for assorted reasons including "I don't know what $item is so I don't know how to check what category it is in". If you can at least figure out that part, if ($item->???() != "courses") { Quote Link to comment https://forums.phpfreaks.com/topic/309972-editing-a-code/#findComment-1573988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.