Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?

WooCommerce allows you to replicate/replace it’s template files by using the exact same file name and placing them in your theme directory using the same path structure they have. So in your theme directory, you add a folder called woocommerce and then within that, you place folder and template files the same way they have the organized.

So you would be creating the following: yourtheme/woocommerce/global/sidebar.php

You can read all about the whole process here: https://docs.woocommerce.com/document/template-structure/

Now, in that file, we have the following line: get_sidebar( 'shop' );

You’ll want to replace that with: get_sidebar( 'shop-yourtheme' );

Not in the WooCommerce one, but in the duplicate you created in your theme.

Now, in your theme directory you want to create a new file called: sidebar-shop-yourtheme.php.

In your functions.php you have to register a new sidebar:

<?php if ( function_exists ('register_sidebar')) { 
    register_sidebar ('shop-yourtheme'); 
} ?>

And NOW we get to the point where you can add your own PHP code into the sidebar. Open your new sidebar-shop-yourtheme.php and add the following:

<?php
/**
* The shop sidebar widget area
* @package yourtheme
*/
if( !is_active_sidebar( 'shop-yourtheme' ) ) {
    return;
}
?>
<aside id="secondary" class="widget-area">
<?php
    // Start Adding your PHP here.
    dynamic_sidebar( 'shop-yourtheme' );
?>
</aside><!-- #secondary -->

As indicated in the code snippet, if you want your custom PHP appearing before the widgets start adding it above the dynamic_sidebar().