Move manual fix applied to plugin source code to theme functions.php
or as Code Snippet
I've applied a manual fix to a plugin file.
I'd like to make this fix more accessible and scalable by hooking this through the theme's functions.php
or adding it as a snippet using a plugin like Code Snippets.
The Manual Fix applied to plugin file (functions as expected):
/**
* Add admin meta box with actions
*
* @access public
* @return void
*/
public function add_woo_pdf_metabox()
{
global $post;
if (!$post) {
return;
}
/* Manual Fix Applied */
$post_type_order = get_post_type( $post );
echo $post_type_order;
if ($post_type_order != 'shop_order') {
return;
}
/* End Manual Fix */
$order = new WC_Order($post->ID);
if (!$order) {
return;
}
$invoice = $this->get_invoice($post->ID);
if ((is_array($invoice) && !empty($invoice) && $this->opt['woo_pdf_enabled']) || (!is_array($invoice) && $this->opt['woo_pdf_proforma_enabled'] && ($order->status != 'completed' || $this->opt['woo_pdf_enabled'])) || ($this->opt['woo_pdf_enabled'])) {
add_meta_box('woo_pdf_metabox', __('PDF Invoices', 'woo_pdf'), array($this, 'woo_pdf_metabox_content'), 'shop_order', 'side', 'default');
}
}
Adjusted fix saved as Code Snippet using keyword extends
on plugin Class (does not function):
add_action('plugins_loaded', 'regulate_pdf_metabox_appearance'); // hook used to call function
function regulate_pdf_metabox_appearance() { // wrapped in function
if (class_exists('WooPDF')) {
class WooPDF_custom extends WooPDF {
/**
* Add admin meta box with actions
*
* @access public
* @return void
*/
function add_woo_pdf_metabox() {
global $post;
if (!$post) {
return;
}
/* Manual Fix Applied */
$post_type_order = get_post_type( $post );
if ($post_type_order != 'shop_order') {
return;
}
$order = new WC_Order($post->ID);
if (!$order) {
return;
}
$invoice = $this->get_invoice($post->ID);
if ((is_array($invoice) && !empty($invoice) && $this->opt['woo_pdf_enabled']) || (!is_array($invoice) && $this->opt['woo_pdf_proforma_enabled'] && ($order->status != 'completed' || $this->opt['woo_pdf_enabled'])) || ($this->opt['woo_pdf_enabled'])) {
add_meta_box('woo_pdf_metabox', __('PDF Invoices', 'woo_pdf'), array($this, 'woo_pdf_metabox_content'), 'shop_order', 'side', 'default');
}
}
}
}
}
What is required in the code above to have the same fix work using extends
and inserting it into the theme's functions.php
or through a Code Snippet?
plugins_loaded
hook to call it (question updated) - which I had assumed would call the name of the extended class. This is not working either. Should I be using another hook or filter?WC_Coupon
.WooPDF_custom
.