<?php
/**
 * Use plugin checkout coupon template (inner flex row for field + button).
 *
 * @package storzen
 */

if (! defined('ABSPATH')) {
	exit;
}

/**
 * @param string $template      Path to template.
 * @param string $template_name Template name.
 * @param array  $args          Args.
 * @param string $template_path Path.
 * @param string $default_path  Default path.
 * @return string
 */
function storzen_wc_get_template_form_coupon($template, $template_name, $args, $template_path, $default_path)
{
	if ('checkout/form-coupon.php' !== $template_name) {
		return $template;
	}
	if (! apply_filters('storzen_use_checkout_form_coupon_template', true)) {
		return $template;
	}
	$plugin_tpl = STORZEN_ROOT_PATH . 'woocommerce/checkout/form-coupon.php';
	return is_readable($plugin_tpl) ? $plugin_tpl : $template;
}
add_filter('wc_get_template', 'storzen_wc_get_template_form_coupon', 10, 5);
