WoordPress WooCommerce get logout url

In this post we ate going to learn about woocommerce get logout url and lets make that step by step

First: get the my account page id by using the code get_option( ‘woocommerce_myaccount_page_id’ );

Second: check if there is any myaccount page id

Third: get the parmalink by passing the myaccount page id through the function get_permalink( $myaccount_page_id )

Fourth: now get the logout url by passing myaccount url through the function wp_logout_url( get_permalink( $myaccount_page_id ) )

Fifth: Check if there is ssl checkout

Sixth: now replace http: to https:

Now you can print the logout url

Here is the code to get woocommerce logout url.

<?php
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );

if ( $myaccount_page_id ) {

$logout_url = wp_logout_url( get_permalink( $myaccount_page_id ) );

if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' )
$logout_url = str_replace( 'http:', 'https:', $logout_url );
}
?>

Thanks for Reading

Share The Post On -

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.