Skip to content

Commit db1fa07

Browse files
committed
Update
1 parent 83923e9 commit db1fa07

15 files changed

Lines changed: 161 additions & 307 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
- id: taplo-lint
4646

4747
- repo: https://github.com/rtts/djhtml
48-
rev: 3.0.9 # Without leading 'v'
48+
rev: 3.0.10 # Without leading 'v'
4949
hooks:
5050
# - id: djhtml
5151
- id: djcss
@@ -73,7 +73,7 @@ repos:
7373
# args: [--rules=@PSR12]
7474

7575
- repo: https://github.com/astral-sh/ruff-pre-commit
76-
rev: v0.13.3
76+
rev: v0.14.0
7777
hooks:
7878
- id: ruff
7979
args: ["--fix", "--exit-non-zero-on-fix", "--ignore=B007,B023,C408,D103,E203,E266,E402,E501,F821,S105,S110,S310,SIM105"] # ruff-pre-commit does not recognize these rule selectors: B902,CM001,S410,SCS109,W503,W504

technology/git/pre-commit/.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
- id: taplo-lint
4646

4747
- repo: https://github.com/rtts/djhtml
48-
rev: 3.0.9 # Without leading 'v'
48+
rev: 3.0.10 # Without leading 'v'
4949
hooks:
5050
# - id: djhtml
5151
- id: djcss
@@ -73,7 +73,7 @@ repos:
7373
# args: [--rules=@PSR12]
7474

7575
- repo: https://github.com/astral-sh/ruff-pre-commit
76-
rev: v0.13.3
76+
rev: v0.14.0
7777
hooks:
7878
- id: ruff
7979
args: ["--fix", "--exit-non-zero-on-fix", "--ignore=B007,B023,C408,D103,E203,E266,E402,E501,F821,S105,S110,S310,SIM105"] # ruff-pre-commit does not recognize these rule selectors: B902,CM001,S410,SCS109,W503,W504
Lines changed: 85 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,101 @@
11
<?php
22
// WooCommerce - Display product currency and price inside "Add to Cart" button
3-
// Last update: 2024-09-17
3+
// Last update: 2025-10-08
44

55
if (class_exists('WooCommerce') && WC()) {
66

7-
add_filter($hook_name = 'woocommerce_product_single_add_to_cart_text', $callback = 'woocommerce_add_to_cart_product_price', $priority = 10, $accepted_args = 2);
7+
add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_add_to_cart_product_price', 10, 2);
88

99
function woocommerce_add_to_cart_product_price($button_text, $product)
1010
{
11-
if (is_product()) {
12-
// Get product price
13-
$product_price = wc_get_price_to_display($product);
14-
15-
// Check if the product is a variable product
16-
if ($product->is_type('variable')) {
17-
// Get variations data
18-
$variations_data = array_column($product->get_available_variations(), 'display_price', 'variation_id');
19-
?>
20-
<script>
21-
jQuery(function($) {
22-
// JSON data for variations
23-
const jsonData = <?php echo json_encode($variations_data); ?>;
24-
const inputVID = 'input.variation_id';
25-
const quantityInput = 'input[name="quantity"]';
26-
const currencySymbol = '<?php echo esc_html(get_woocommerce_currency_symbol()); ?>';
27-
const currencyPosition = '<?php echo esc_html(get_option("woocommerce_currency_pos")); ?>';
28-
const currencyDecimals = '<?php echo esc_html(wc_get_price_decimals()); ?>';
29-
const locale = 'de-DE';
30-
31-
// Number formatter for price
32-
const formatter = new Intl.NumberFormat(locale, {
33-
minimumFractionDigits: parseInt(currencyDecimals),
34-
maximumFractionDigits: parseInt(currencyDecimals)
35-
});
36-
37-
// Function to format price based on currency position
38-
function formatPrice(price) {
39-
let formattedPrice = formatter.format(price);
40-
switch(currencyPosition) {
41-
case 'left':
42-
return currencySymbol + formattedPrice;
43-
case 'right':
44-
return formattedPrice + currencySymbol;
45-
case 'left_space':
46-
return currencySymbol + ' ' + formattedPrice;
47-
case 'right_space':
48-
return formattedPrice + ' ' + currencySymbol;
49-
default:
50-
return currencySymbol + formattedPrice; // default to left if unknown position
51-
}
52-
}
53-
54-
// Function to update price
55-
function updatePrice() {
56-
const vid = $(inputVID).val();
57-
const quantity = parseInt($(quantityInput).val()) || 1;
58-
if (vid && jsonData[vid] !== undefined) {
59-
const price = jsonData[vid] * quantity;
60-
const priceHtml = formatPrice(price);
61-
$("button.single_add_to_cart_button span[data-price='true']").remove();
62-
$(".single_add_to_cart_button").append("<span data-price='true'> - " + priceHtml + "</span>"); // Append price to button
63-
} else {
64-
$("button.single_add_to_cart_button span[data-price='true']").remove(); // Remove existing price if variation is not selected
65-
}
66-
}
67-
68-
// Initial price update
69-
updatePrice();
70-
// Event listeners for variation ID and quantity changes
71-
$(inputVID + ', ' + quantityInput).on('change', updatePrice);
72-
// Event listener for quantity change using buttons
73-
$('button.plus, button.minus').on('click', function() {
74-
setTimeout(updatePrice, 0);
75-
});
76-
});
77-
</script>
78-
<?php
79-
} else {
80-
// For single products, display regular product price
81-
?>
82-
<script>
83-
jQuery(function($) {
84-
const quantityInput = 'input[name="quantity"]';
85-
const currencySymbol = '<?php echo esc_html(get_woocommerce_currency_symbol()); ?>';
86-
const currencyPosition = '<?php echo esc_html(get_option("woocommerce_currency_pos")); ?>';
87-
const currencyDecimals = '<?php echo esc_html(wc_get_price_decimals()); ?>';
88-
const basePrice = <?php echo $product_price; ?>;
89-
const locale = 'de-DE';
90-
91-
// Number formatter for price
92-
const formatter = new Intl.NumberFormat(locale, {
93-
minimumFractionDigits: parseInt(currencyDecimals),
94-
maximumFractionDigits: parseInt(currencyDecimals)
95-
});
11+
if (!is_product()) {
12+
return $button_text;
13+
}
9614

97-
// Function to format price based on currency position
98-
function formatPrice(price) {
99-
let formattedPrice = formatter.format(price);
100-
switch(currencyPosition) {
101-
case 'left':
102-
return currencySymbol + formattedPrice;
103-
case 'right':
104-
return formattedPrice + currencySymbol;
105-
case 'left_space':
106-
return currencySymbol + ' ' + formattedPrice;
107-
case 'right_space':
108-
return formattedPrice + ' ' + currencySymbol;
109-
default:
110-
return currencySymbol + formattedPrice; // default to left if unknown position
111-
}
112-
}
15+
// Common configuration for both product types
16+
$currency_config = sprintf(
17+
'const currencySymbol = %s;
18+
const currencyPosition = %s;
19+
const currencyDecimals = %s;
20+
const locale = "de-DE";
21+
22+
const formatter = new Intl.NumberFormat(locale, {
23+
minimumFractionDigits: parseInt(currencyDecimals),
24+
maximumFractionDigits: parseInt(currencyDecimals)
25+
});
26+
27+
function formatPrice(price) {
28+
const formattedPrice = formatter.format(price);
29+
switch(currencyPosition) {
30+
case "left": return currencySymbol + formattedPrice;
31+
case "right": return formattedPrice + currencySymbol;
32+
case "left_space": return currencySymbol + " " + formattedPrice;
33+
case "right_space": return formattedPrice + " " + currencySymbol;
34+
default: return currencySymbol + formattedPrice;
35+
}
36+
}',
37+
wp_json_encode(get_woocommerce_currency_symbol()),
38+
wp_json_encode(get_option('woocommerce_currency_pos')),
39+
wp_json_encode(wc_get_price_decimals())
40+
);
11341

114-
// Function to update price
115-
function updatePrice() {
116-
const quantity = parseInt($(quantityInput).val()) || 1;
117-
const price = basePrice * quantity;
118-
const priceHtml = formatPrice(price);
119-
$("button.single_add_to_cart_button span[data-price='true']").remove();
120-
$(".single_add_to_cart_button").append("<span data-price='true'> - " + priceHtml + "</span>"); // Append price to button
42+
if ($product->is_type('variable')) {
43+
$variations_data = array_column($product->get_available_variations(), 'display_price', 'variation_id');
44+
?>
45+
<script>
46+
jQuery(function($) {
47+
const jsonData = <?php echo wp_json_encode($variations_data); ?>;
48+
const $button = $(".single_add_to_cart_button");
49+
const $varInput = $("input.variation_id");
50+
const $qtyInput = $('input[name="quantity"]');
51+
52+
<?php echo $currency_config; ?>
53+
54+
function updatePrice() {
55+
const vid = $varInput.val();
56+
const quantity = parseInt($qtyInput.val()) || 1;
57+
58+
$button.find('span[data-price]').remove();
59+
60+
if (vid && jsonData[vid] !== undefined) {
61+
const priceHtml = formatPrice(jsonData[vid] * quantity);
62+
$button.append('<span data-price> - ' + priceHtml + '</span>');
12163
}
122-
123-
// Initial price update
124-
updatePrice();
125-
// Event listeners for quantity changes
126-
$(quantityInput).on('change', updatePrice);
127-
// Event listener for quantity change using buttons
128-
$('button.plus, button.minus').on('click', function() {
129-
setTimeout(updatePrice, 0);
130-
});
131-
});
132-
</script>
133-
<?php
134-
}
135-
136-
return $button_text;
64+
}
65+
66+
updatePrice();
67+
$varInput.add($qtyInput).on('change', updatePrice);
68+
$('button.plus, button.minus').on('click', () => setTimeout(updatePrice, 0));
69+
});
70+
</script>
71+
<?php
72+
} else {
73+
$product_price = wc_get_price_to_display($product);
74+
?>
75+
<script>
76+
jQuery(function($) {
77+
const basePrice = <?php echo $product_price; ?>;
78+
const $button = $(".single_add_to_cart_button");
79+
const $qtyInput = $('input[name="quantity"]');
80+
81+
<?php echo $currency_config; ?>
82+
83+
function updatePrice() {
84+
const quantity = parseInt($qtyInput.val()) || 1;
85+
const priceHtml = formatPrice(basePrice * quantity);
86+
87+
$button.find('span[data-price]').remove();
88+
$button.append('<span data-price> - ' + priceHtml + '</span>');
89+
}
90+
91+
updatePrice();
92+
$qtyInput.on('change', updatePrice);
93+
$('button.plus, button.minus').on('click', () => setTimeout(updatePrice, 0));
94+
});
95+
</script>
96+
<?php
13797
}
13898

13999
return $button_text;
140100
}
141-
142101
}

technology/web-development/wordpress/woocommerce/woocommerce-get-the-app-message-removal.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

technology/web-development/wordpress/woocommerce/woocommerce-order-add-date-cancelled.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

technology/web-development/wordpress/woocommerce/woocommerce-order-country-display-force.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

technology/web-development/wordpress/woocommerce/woocommerce-phastpress-disable.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

technology/web-development/wordpress/woocommerce/woocommerce-product-remove-image-effects.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

technology/web-development/wordpress/woocommerce/woocommerce-reset-variations-link-disable.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)