Friday, October 23, 2020

Woocommerce: My Account Page Customisation

/**

 * My ACCOUNT PAGE CUSTOMISATION

 */


//Merge Two "My Account" Tabs @ WooCommerce Account


// Remove Downloads Tab (downloads in this case)

 

add_filter( 'woocommerce_account_menu_items', 'remove_downloads_my_account', 999 );

  

function remove_downloads_my_account( $items ) {

unset($items['downloads']);

return $items;

}



// 1. First, hide the tab that needs to be merged/moved (edit-address in this case)

 

add_filter( 'woocommerce_account_menu_items', 'remove_address_my_account', 999 );

  

function remove_address_my_account( $items ) {

unset($items['edit-address']);

return $items;

}

 


// 1. First, hide the tab that needs to be merged/moved (payment-methods in this case)

 

add_filter( 'woocommerce_account_menu_items', 'remove_payment_my_account', 999 );

  

function remove_payment_my_account( $items ) {

unset($items['payment-methods']);

return $items;

}


// 2. Second, print the ex tab content into an existing tab (edit-account in this case)

 

add_action( 'woocommerce_account_edit-account_endpoint', 'woocommerce_account_edit_address' );

//add_action( 'woocommerce_account_edit-account_endpoint', 'woocommerce_account_payment_methods' );


/**

  * Register new endpoints to use inside My Account page.

  */


 add_action( 'init', 'my_account_new_endpoints' );


 function my_account_new_endpoints() {

  add_rewrite_endpoint( 'warranty-requests', EP_ROOT | EP_PAGES );

 }


/**

  * Get new endpoint content

  */


  // Warranty

 add_action( 'woocommerce_warranty_requests_endpoint', 'warranty_requests_endpoint_content' );

 function warranty_requests_endpoint_content() {

     get_template_part('warranty-requests');

 }


// Rename, re-order my account menu items

function reorder_my_account_menu() {

    $neworder = array(

        'dashboard'          => __( 'Dashboard', 'woocommerce' ),

        'orders'             => __( 'Orders', 'woocommerce' ),

        'wishlist'      => __( 'Wishlist', 'woocommerce' ),

        //‘edit-address'       => __( 'Addresses', 'woocommerce' ),

        'edit-account'       => __( 'Account Details', 'woocommerce' ),

        'warranty-requests'       => __( 'Limited Warranty', 'woocommerce' ),

       'customer-logout'    => __( 'Logout', 'woocommerce' ),

    );

    return $neworder;

}

add_filter ( 'woocommerce_account_menu_items', 'reorder_my_account_menu' );



// Display the product thumbnail in order view pages like Uniqlo

add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );

function display_product_image_in_order_item( $item_name, $item, $is_visible ) {

    // Targeting view order pages only

    if( is_wc_endpoint_url( 'view-order' ) ) {

        // Get the WC_Product object (from order item)

        $product   = $item->get_product(); 


        // Testing if the product exist in Woocommerce <== UPDATE

        if( $product && is_object( $product ) ) {

            // Get the product thumbnail (from product object)

            $thumbnail = $product->get_image(array( 36, 36)); 

            // Avoiding empty thumbnail (updated)

            if( $product->get_image_id() > 0 )

                $item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;

        } else {

            // When product doesn't exist, we get the name from the order item (with no thumbnail)

            $item_name = $item->get_name();

        }

    }

    return $item_name;

}


No comments: