i want to change the output of a method inside the class of a plugin from the child function.php without changing the plugin's file. The output i want to change is that instead of a common a href, it uses the template button array. The thing is that the output of the method you get is a shortcode (this shortcode below that you can insert to any template you want). I don't know how to change this method from the child function.php. I modded this plugin file, it works, but it means i don't get to update the plugin without loosing the new button.
echo do_shortcode( '[bewpi-download-invoice title="Download (PDF) Invoice {formatted_invoice_number}" order_id="' . $order->id . '"]' );
Here is the method inside the be-woocommerce-pdf-invoices.php class
public function download_invoice_shortcode( $atts ) {
if ( ! isset( $atts['order_id'] ) || 0 === intval( $atts['order_id'] ) ) {
return;
}
// by default order status should be Processing or Completed.
$order = wc_get_order( $atts['order_id'] );
if ( ! $order->is_paid() ) {
return;
}
if ( ! BEWPI_Invoice::exists( $order->id ) ) {
return;
}
$url = add_query_arg( array(
'bewpi_action' => 'view',
'post' => $order->id,
'nonce' => wp_create_nonce( 'view' ),
) );
$invoice = new BEWPI_Invoice( $order->id );
$tags = array(
'{formatted_invoice_number}' => $invoice->get_formatted_number(),
'{order_number}' => $order->id,
'{formatted_invoice_date}' => $invoice->get_formatted_invoice_date(),
'{formatted_order_date}' => $invoice->get_formatted_order_date(),
);
// find and replace placeholders.
$title = str_replace( array_keys( $tags ), array_values( $tags ), $atts['title'] );
// MOD OF THE PLUGIN
thegem_button(array(
'tag' => 'a',
'href' => esc_attr( $url ),
'text' => esc_html__($title, 'thegem' ),
'style' => 'outline',
'size' => 'medium',
'extra_class' => 'checkout-exit',
'attributes' => array(
'value' => esc_attr__( $title, 'thegem' ),
)
), true);
// ORIGINAL OUTPUT
// printf( '<a href="%1$s">%2$s</a>', esc_attr( $url ), esc_html( $title ) );
}
MOD OF THE PLUGIN is the new code i added. The original output i put it to comment. Any suggestion is welcome of course. Thanks in advance