Highlighting Import List and Other Post Status on Front End

Hello, I was having some trouble with many products on the front end. Since AliWoo displays the products on the front end for administrators, as well as WP displaying Private posts, I decided to create this little code snippet to help me identify the products status. I also created another one for the products page that will display the status and an 'Edit' button in the upper right corner of your product post.

You can drop these snippets at the end of your functions.php file and then you should see the changes on the front end.
Edit to suit. YMMV. Only administrators or rather those with permission to 'edit_posts' will see the flags.

here is an example of the catalog and product pages:
catalog_status47912.jpg
product_statusb60cf.jpg



this bit here is for the product page.

Code:
add_action( 'woocommerce_before_single_product_summary', 'display_pstatus_post' );

function display_pstatus_post() {
echo '<div style="position:relative; width:100%; text-align:right;">';
    if (is_user_logged_in() && (current_user_can( 'edit_posts' ) ))
            {
            edit_post_link('[edit] ');
            $ID = get_the_ID();
            $pstatus = get_post_status ( $ID );
            if ( $pstatus == 'publish' ) {
                echo '<span style="color:#fff; background:#3aa425; font-weight:400; padding: 0 3px;">PUBLIC</span>';
                    } else if ( $pstatus == 'importlist' ) {
                echo '<span style="color:#fff; background:#a70000; font-weight:400; padding: 0 3px;">IMPORT LIST</span>';
                    } else if ( $pstatus == 'draft' ) {
                echo '<span style="color:#fff; background:#a70000; font-weight:400; padding: 0 3px;">DRAFT</span>';
                    } else if ( $pstatus == 'pending' ) {
                echo '<span style="color:#fff; background:#a70000; font-weight:400; padding: 0 3px;">PENDING</span>';
                } else if ( $pstatus == 'private' ) {
                echo '<span style="color:#fff; background:#a70000; font-weight:400; padding: 0 3px;">PRIVATE</span>';
            }
        }   
            
        echo '</div>';
}


this bit here is for the catalog pages.

Code:
add_action( 'woocommerce_before_shop_loop_item', 'display_pstatus_catalog' );

function display_pstatus_catalog() {
if (is_user_logged_in() && (current_user_can( 'edit_posts' ) ))
            {
            $ID = get_the_ID();
            $pstatus = get_post_status ( $ID );
            if ( $pstatus == 'publish' ) {
                    echo '<div style="color:#fff; background:#3aa425; font-weight:700; line-height:2;">PUBLIC</div>';
                } else if ( $pstatus == 'importlist' ) {
                    echo '<div style="color:#fff; background:#a70000; font-weight:700; line-height:2;">IMPORT LIST</div>';
                } else if ( $pstatus == 'draft' ) {
                    echo '<div style="color:#fff; background:#a70000; font-weight:700; line-height:2;">DRAFT</div>';
                } else if ( $pstatus == 'pending' ) {
                    echo '<div style="color:#fff; background:#a70000; font-weight:700; line-height:2;">PENDING</div>';
                } else if ( $pstatus == 'private' ) {
                    echo '<div style="color:#fff; background:#a70000; font-weight:700; line-height:2;">PRIVATE</div>';
            }
        }   
        
}

I hope you find it useful. Good luck :D

-451
 
Top