I would begin by either creating a child theme or a custom plugin to contain your custom code, otherwise your work will be overwritten during updates. Copy the WC widget callback function to your code page, giving it a new name. Modify it as needed. Register your widget callback with register_widget().
Your widget will now appear with the others on the widget page or customizer panel. Drag it to the sidebar of your choice and enjoy the results! (or more than likely, begin debugging your code. Nothing new there ?? )
Oddly, this approach is unusual in that it does not involve hooking actions or filters, which are the usual ways to customize WP. I recommend you study up on implementing action and filter hooks anyway, they are the primary way to alter WP functionality. You will end up using them sooner or later. As you may know, we never alter core code (never other’s plugins and themes too). Hooks are the way these elements are altered.
In fact, the WC widget may have filter hooks where you can alter the functionality without going through making a copy. Your changes seemed major enough that altering the callback directly sounded more efficient. But before getting too involved with altering the callback, it’d be worth investigating if any filter hooks are available to allow you to do what you want.
Filters are always invoked by apply_filters()
or apply_filters_ref_array()
. If nothing useful appears in the widget callback, sometimes functions used within may have usable filters. It can take some digging to determine if a filter hook is feasible. Rewriting the callback as a new widget will certainly work no matter what.