Skip to content

Instantly share code, notes, and snippets.

@wpweb101
Created October 30, 2023 12:01
Show Gist options
  • Save wpweb101/719bdb66f3f97bf2375cfc7ed8a30bf4 to your computer and use it in GitHub Desktop.
Save wpweb101/719bdb66f3f97bf2375cfc7ed8a30bf4 to your computer and use it in GitHub Desktop.
Adding Custom shortcode value in PDF voucher
function woo_vou_pdf_template_replace_shortcodes( $voucher_template_html, $orderid, $item_key, $items, $voucodes, $productid ) {
$prefix = WOO_VOU_META_PREFIX;
$woo_order = wc_get_order( $orderid );
// Check if order exists
if ( ! $woo_order ) {
return $voucher_template_html;
}
// Get order item
$order_item = $woo_order->get_item( $item_key );
// Check if order item exists
if ( ! $order_item ) {
return $voucher_template_html;
}
// Get recipient from name
$recipient_from_name = $order_item->get_meta( $prefix.WOO_VOU_CSTM_RECIPIENT_FIELD );
// Check if recipient from name exists
if ( $recipient_from_name ) {
// Access the 'value' key in the meta data
$recipient_from_name_value = isset( $recipient_from_name['value'] ) ? $recipient_from_name['value'] : '';
// Replace the placeholder in the template with the recipient from name
$voucher_template_html = str_replace( '{recipient_from_name}', $recipient_from_name_value, $voucher_template_html );
}
return $voucher_template_html;
}
// Add filter to replace voucher template shortcodes in download pdf
add_filter('woo_vou_pdf_template_inner_html', 'woo_vou_pdf_template_replace_shortcodes', 10, 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment