Skip to content

Instantly share code, notes, and snippets.

@axxe16
Created April 17, 2020 06:18
Show Gist options
  • Save axxe16/0c3b7f64f29cb1dbf1801d6e78955ac8 to your computer and use it in GitHub Desktop.
Save axxe16/0c3b7f64f29cb1dbf1801d6e78955ac8 to your computer and use it in GitHub Desktop.
Aggiungi una voce al pannello riservato utente woocommerce #woocommerce #privato #reserved #tab
/**
* @snippet WooCommerce Add New Tab @ My Account
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 3.5.7
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
// ------------------
// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error
function fcs_add_corsi_endpoint() {
add_rewrite_endpoint( 'corsi', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'fcs_add_corsi_endpoint' );
// ------------------
// 2. Add new query var
function fcs_corsi_query_vars( $vars ) {
$vars[] = 'corsi';
return $vars;
}
add_filter( 'query_vars', 'fcs_corsi_query_vars', 0 );
// ------------------
// 3. Insert the new endpoint into the My Account menu
function fcs_add_corsi_link_my_account( $items ) {
$items['corsi'] = 'Corsi';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'fcs_add_corsi_link_my_account' );
// ------------------
// 4. Add content to the new endpoint
function fcs_corsi_content() {
echo '<h3>Corsi Formazione Continua San Marco</h3><p>Benvenuto nella sezione decicata ai corsi</p>';
//dati utente
$userdata = get_userdata(get_current_user_id());
$user_plans = YITH_WCMBS_Membership_Helper()->get_memberships_by_user( get_current_user_id() );
print_rb($user_plans);
//ciclo tutti le membership attivate per l'utente corrente
$args = array(
'post_type' => 'ywcmbs-membership',
'meta_key' => '_user_id',
'meta_value' => get_current_user_id(),
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
$infoPiani = array(); //info relativi ai piani sottoscritti dall'utente
if ( $loop->have_posts() ) {
$k = 0;
while ( $loop->have_posts() ) : $loop->the_post();
$infoPiani[$k]['titolo-membership'] = get_the_title();
$infoPiani[$k]['id-membership'] = get_the_ID();
if(get_post_meta(get_the_ID(),'_order_id')):
$infoPiani[$k]['id-ordine'] = get_post_meta(get_the_ID(),'_order_id')[0];
//recupero corsi associati all'ordine
$order = wc_get_order( get_post_meta(get_the_ID(),'_order_id')[0] );
$items = $order->get_items();
foreach ( $items as $i => $item ) {
$infoPiani[$k]['corsi'][$i]['titolo-corso'] = $item->get_name();
$infoPiani[$k]['corsi'][$i]['id-corso'] = $item->get_product_id();
}
endif;
$k++;
endwhile;
print_rb($infoPiani);
}
wp_reset_postdata();
}
add_action( 'woocommerce_account_corsi_endpoint', 'fcs_corsi_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment