'', 'button' => '' ], $atts );
$gift_card_id = intval( $atts['id'] );
// Prevent issues with elementor, beaver builder (same guard as [rr_form]).
if ( is_admin() || isset( $_GET['fl_builder'] ) || wp_doing_ajax() ) {
return '
Alex Reservations gift voucher button ID=' . $gift_card_id . ' will be displayed here.
';
}
if ( ! $gift_card_id ) {
return '';
}
// Resolve the gift card product and derive its restaurant.
$product = \Alexr\Settings\GiftCard::find( $gift_card_id );
if ( ! $product || ! $product->active ) {
return '';
}
$restaurant_id = intval( $product->restaurant_id );
$restaurant = \Alexr\Models\Restaurant::find( $restaurant_id );
if ( ! $restaurant ) {
return '';
}
// HARD gate: selling requires the Gift Vouchers addon on this restaurant.
if ( ! alexr_gift_cards_enabled( $restaurant ) ) {
return current_user_can( 'manage_options' )
? ''
: '';
}
// Assets: PRO build preferred, free fallback.
$voucher_dir = ALEXR_PLUGIN_URL . 'assets/voucher-mix/';
$version = ALEXR_VERSION;
if ( defined( 'ALEXR_PRO_VERSION' ) ) {
$voucher_dir = ALEXR_PRO_PLUGIN_URL . 'assets/voucher-mix/';
$version = ALEXR_PRO_VERSION;
}
wp_enqueue_style( 'rr-voucher-css', $voucher_dir . 'index.css', [], $version );
wp_enqueue_script( 'rr-voucher-main', $voucher_dir . 'main.js', [], $version, true );
// Page-global (same for every button on the page).
wp_localize_script( 'rr-voucher-main', 'rr_config', alexr_get_config() );
wp_localize_script( 'rr-voucher-main', 'rr_translations', alexr_get_translations() );
// Per-button config → data-config so multiple [rr_voucher] on one page don't clash.
$config = [
'restaurant_id' => $restaurant_id,
'restaurant_name' => $restaurant->name,
'nonce' => evavel_tenant_create_nonce( $restaurant_id ),
'currency' => strtolower( $restaurant->currency ),
'currency_symbol' => \Alexr\Enums\CurrencyType::symbolFor( $restaurant->currency ),
'language' => $restaurant->language,
'button' => sanitize_text_field( $atts['button'] ),
'product' => \Alexr\Settings\GiftCard::mapPublicProduct( $product ),
];
return '';
}