You've already forked wc-tier-and-package-prices
Release version 1.0.1
- Add Twig template engine integration - Migrate all templates to Twig format - Add German (Switzerland, Informal) translation - Improve template organization and security - Add Composer dependency management - Create comprehensive changelog
This commit is contained in:
36
templates/admin/package-row.twig
Normal file
36
templates/admin/package-row.twig
Normal file
@@ -0,0 +1,36 @@
|
||||
{#
|
||||
# Admin Package Row Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
# @var int index
|
||||
# @var array package
|
||||
#}
|
||||
<div class="wc-tpp-package-row">
|
||||
<p class="form-field">
|
||||
<label>{{ 'Quantity'|__('wc-tier-package-prices') }}</label>
|
||||
<input type="number"
|
||||
name="_wc_tpp_packages[{{ index|esc_attr }}][qty]"
|
||||
value="{{ package.qty|default('')|esc_attr }}"
|
||||
placeholder="{{ 'e.g., 10'|__('wc-tier-package-prices') }}"
|
||||
min="1"
|
||||
step="1"
|
||||
class="short">
|
||||
</p>
|
||||
<p class="form-field">
|
||||
<label>{{ 'Fixed Price'|__('wc-tier-package-prices') }}</label>
|
||||
<input type="text"
|
||||
name="_wc_tpp_packages[{{ index|esc_attr }}][price]"
|
||||
value="{{ package.price|default('')|esc_attr }}"
|
||||
placeholder="{{ 'e.g., 99.99'|__('wc-tier-package-prices') }}"
|
||||
class="short wc_input_price">
|
||||
</p>
|
||||
<p class="form-field">
|
||||
<label>{{ 'Label (Optional)'|__('wc-tier-package-prices') }}</label>
|
||||
<input type="text"
|
||||
name="_wc_tpp_packages[{{ index|esc_attr }}][label]"
|
||||
value="{{ package.label|default('')|esc_attr }}"
|
||||
placeholder="{{ 'e.g., Starter Pack'|__('wc-tier-package-prices') }}"
|
||||
class="short">
|
||||
</p>
|
||||
<button type="button" class="button wc-tpp-remove-package">{{ 'Remove'|__('wc-tier-package-prices') }}</button>
|
||||
</div>
|
||||
53
templates/admin/settings-page.twig
Normal file
53
templates/admin/settings-page.twig
Normal file
@@ -0,0 +1,53 @@
|
||||
{#
|
||||
# Admin Settings Page Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
#}
|
||||
<div class="wrap">
|
||||
<h1>{{ get_admin_page_title()|esc_html }}</h1>
|
||||
<form action="options.php" method="post">
|
||||
{{ settings_fields('wc_tpp_settings') }}
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wc_tpp_enable_tier_pricing">{{ 'Enable Tier Pricing'|__('wc-tier-package-prices') }}</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" id="wc_tpp_enable_tier_pricing" name="wc_tpp_enable_tier_pricing" value="yes" {{ checked(get_option('wc_tpp_enable_tier_pricing'), 'yes')|raw }}>
|
||||
<p class="description">{{ 'Enable tier pricing for products'|__('wc-tier-package-prices') }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wc_tpp_enable_package_pricing">{{ 'Enable Package Pricing'|__('wc-tier-package-prices') }}</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" id="wc_tpp_enable_package_pricing" name="wc_tpp_enable_package_pricing" value="yes" {{ checked(get_option('wc_tpp_enable_package_pricing'), 'yes')|raw }}>
|
||||
<p class="description">{{ 'Enable fixed-price packages for products'|__('wc-tier-package-prices') }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wc_tpp_display_table">{{ 'Display Pricing Table'|__('wc-tier-package-prices') }}</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" id="wc_tpp_display_table" name="wc_tpp_display_table" value="yes" {{ checked(get_option('wc_tpp_display_table'), 'yes')|raw }}>
|
||||
<p class="description">{{ 'Show tier and package pricing table on product pages'|__('wc-tier-package-prices') }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wc_tpp_display_position">{{ 'Display Position'|__('wc-tier-package-prices') }}</label>
|
||||
</th>
|
||||
<td>
|
||||
<select id="wc_tpp_display_position" name="wc_tpp_display_position">
|
||||
<option value="before_add_to_cart" {{ selected(get_option('wc_tpp_display_position'), 'before_add_to_cart')|raw }}>{{ 'Before Add to Cart'|__('wc-tier-package-prices') }}</option>
|
||||
<option value="after_add_to_cart" {{ selected(get_option('wc_tpp_display_position'), 'after_add_to_cart')|raw }}>{{ 'After Add to Cart'|__('wc-tier-package-prices') }}</option>
|
||||
<option value="after_price" {{ selected(get_option('wc_tpp_display_position'), 'after_price')|raw }}>{{ 'After Price'|__('wc-tier-package-prices') }}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{{ submit_button() }}
|
||||
</form>
|
||||
</div>
|
||||
28
templates/admin/tier-row.twig
Normal file
28
templates/admin/tier-row.twig
Normal file
@@ -0,0 +1,28 @@
|
||||
{#
|
||||
# Admin Tier Row Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
# @var int index
|
||||
# @var array tier
|
||||
#}
|
||||
<div class="wc-tpp-tier-row">
|
||||
<p class="form-field">
|
||||
<label>{{ 'Minimum Quantity'|__('wc-tier-package-prices') }}</label>
|
||||
<input type="number"
|
||||
name="_wc_tpp_tiers[{{ index|esc_attr }}][min_qty]"
|
||||
value="{{ tier.min_qty|default('')|esc_attr }}"
|
||||
placeholder="{{ 'e.g., 10'|__('wc-tier-package-prices') }}"
|
||||
min="1"
|
||||
step="1"
|
||||
class="short">
|
||||
</p>
|
||||
<p class="form-field">
|
||||
<label>{{ 'Price per Unit'|__('wc-tier-package-prices') }}</label>
|
||||
<input type="text"
|
||||
name="_wc_tpp_tiers[{{ index|esc_attr }}][price]"
|
||||
value="{{ tier.price|default('')|esc_attr }}"
|
||||
placeholder="{{ 'e.g., 9.99'|__('wc-tier-package-prices') }}"
|
||||
class="short wc_input_price">
|
||||
</p>
|
||||
<button type="button" class="button wc-tpp-remove-tier">{{ 'Remove'|__('wc-tier-package-prices') }}</button>
|
||||
</div>
|
||||
35
templates/frontend/package-pricing-display.twig
Normal file
35
templates/frontend/package-pricing-display.twig
Normal file
@@ -0,0 +1,35 @@
|
||||
{#
|
||||
# Frontend Package Pricing Display Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
# @var array packages
|
||||
#}
|
||||
<div class="wc-tpp-package-pricing-table">
|
||||
<h3>{{ 'Package Deals'|__('wc-tier-package-prices') }}</h3>
|
||||
<div class="wc-tpp-packages">
|
||||
{% for index, package in packages %}
|
||||
{% set price_per_unit = package.qty > 0 ? package.price / package.qty : 0 %}
|
||||
<div class="wc-tpp-package" data-qty="{{ package.qty|esc_attr }}" data-price="{{ package.price|esc_attr }}">
|
||||
<div class="wc-tpp-package-header">
|
||||
{% if package.label is not empty %}
|
||||
<h4>{{ package.label|esc_html }}</h4>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="wc-tpp-package-details">
|
||||
<div class="wc-tpp-package-qty">
|
||||
<strong>{{ package.qty|esc_html }}</strong> {{ 'pieces'|__('wc-tier-package-prices') }}
|
||||
</div>
|
||||
<div class="wc-tpp-package-price">
|
||||
{{ wc_price(package.price)|raw }}
|
||||
</div>
|
||||
<div class="wc-tpp-package-unit-price">
|
||||
{{ wc_price(price_per_unit)|raw }} {{ 'per unit'|__('wc-tier-package-prices') }}
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="button wc-tpp-select-package" data-package-index="{{ index|esc_attr }}">
|
||||
{{ 'Select Package'|__('wc-tier-package-prices') }}
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
17
templates/frontend/pricing-table.twig
Normal file
17
templates/frontend/pricing-table.twig
Normal file
@@ -0,0 +1,17 @@
|
||||
{#
|
||||
# Frontend Pricing Table Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
# @var object product
|
||||
# @var array tiers
|
||||
# @var array packages
|
||||
#}
|
||||
<div class="wc-tpp-pricing-container">
|
||||
{% if tiers is not empty and get_option('wc_tpp_enable_tier_pricing') == 'yes' %}
|
||||
{% include 'frontend/tier-pricing-table.twig' with {'product': product, 'tiers': tiers} %}
|
||||
{% endif %}
|
||||
|
||||
{% if packages is not empty and get_option('wc_tpp_enable_package_pricing') == 'yes' %}
|
||||
{% include 'frontend/package-pricing-display.twig' with {'packages': packages} %}
|
||||
{% endif %}
|
||||
</div>
|
||||
41
templates/frontend/tier-pricing-table.twig
Normal file
41
templates/frontend/tier-pricing-table.twig
Normal file
@@ -0,0 +1,41 @@
|
||||
{#
|
||||
# Frontend Tier Pricing Table Template
|
||||
#
|
||||
# @package WC_Tier_Package_Prices
|
||||
# @var object product
|
||||
# @var array tiers
|
||||
#}
|
||||
<div class="wc-tpp-tier-pricing-table">
|
||||
<h3>{{ 'Volume Discounts'|__('wc-tier-package-prices') }}</h3>
|
||||
<table class="wc-tpp-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Quantity'|__('wc-tier-package-prices') }}</th>
|
||||
<th>{{ 'Price per Unit'|__('wc-tier-package-prices') }}</th>
|
||||
<th>{{ 'You Save'|__('wc-tier-package-prices') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% set regular_price = product.get_regular_price() %}
|
||||
{% for tier in tiers %}
|
||||
{% set savings = 0 %}
|
||||
{% set savings_percent = 0 %}
|
||||
{% if regular_price > 0 %}
|
||||
{% set savings = regular_price - tier.price %}
|
||||
{% set savings_percent = (savings / regular_price) * 100 %}
|
||||
{% endif %}
|
||||
<tr data-min-qty="{{ tier.min_qty|esc_attr }}" data-price="{{ tier.price|esc_attr }}">
|
||||
<td>{{ tier.min_qty|esc_html }}+</td>
|
||||
<td>{{ wc_price(tier.price)|raw }}</td>
|
||||
<td>
|
||||
{% if savings > 0 %}
|
||||
{{ wc_price(savings)|raw }} ({{ savings_percent|round(2) }}%)
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
Reference in New Issue
Block a user