Skip to content

Instantly share code, notes, and snippets.

@wpweb101
Last active April 24, 2024 10:53
Show Gist options
  • Select an option

  • Save wpweb101/aa5cb1870d077d314f1a to your computer and use it in GitHub Desktop.

Select an option

Save wpweb101/aa5cb1870d077d314f1a to your computer and use it in GitHub Desktop.
Woocommerce PDF Vouchers - Modify Unlimited voucher codes pattern logic
<?php
// You can modify / remove following fields using the filter
// buyername, code_prefix, order_id, data_id, $item_id
// $voucher_codes = array( 'buyername' => $buyername, 'code_prefix' => $code_prefix, 'order_id' => $order_id, 'data_id' => $data_id, 'item_id' => $item_id, 'separator' => '-' );
function woo_vou_unlimited_code_pattern_modification( $voucodes_args = array() ) {
if( $voucodes_args['buyername'] ) {// if you want to remove buyername from pattern
unset( $voucodes_args['buyername'] );
}
//if you want to add any pattern in voucher code
$voucodes_args['pattern'] = 'abcd123'; // it will add a abcd123 at the end of each voucher code
//if you want to change separator
$voucodes_args['separator'] = '_'; // it will change separator from "-" to "_"
return $voucodes_args;
}
add_filter( 'woo_vou_unlimited_code_pattern', 'woo_vou_unlimited_code_pattern_modification' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment