<?php
/**
 * Elena-style add-to-cart quantity markup for the Elementor single-product widget.
 *
 * @package Storzen
 */

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

/**
 * Use plugin quantity template when rendering single-product add-to-cart from our widget.
 *
 * @param string $template      Full path to the located template.
 * @param string $template_name Template name.
 * @param array  $args          Template arguments.
 * @param string $template_path Template path.
 * @param string $default_path  Default path.
 * @return string
 */
function storzen_filter_wc_quantity_template( $template, $template_name, $args, $template_path, $default_path ) {
	if ( 'global/quantity-input.php' !== $template_name ) {
		return $template;
	}
	if ( empty( $GLOBALS['storzen_elena_single_atc'] ) ) {
		return $template;
	}
	$plugin_tpl = STORZEN_ROOT_PATH . 'woocommerce/global/quantity-input.php';
	return is_readable( $plugin_tpl ) ? $plugin_tpl : $template;
}
add_filter( 'wc_get_template', 'storzen_filter_wc_quantity_template', 10, 5 );
