Skip to content

Commit 18653d7

Browse files
feat: more context specific templates
1 parent 89a9c4a commit 18653d7

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

includes/class-wcdp-form.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ public static function order_contains_donation(WC_Order $order): bool
281281
return false;
282282
}
283283

284+
/**
285+
* Return true if the order contains only donation products
286+
* @param WC_Order $order
287+
* @return bool
288+
*/
289+
public static function order_contains_only_donations(WC_Order $order): bool
290+
{
291+
foreach ($order->get_items() as $item) {
292+
if (isset($item['product_id']) && !WCDP_Form::is_donable($item['product_id'])) {
293+
return false;
294+
}
295+
}
296+
return true;
297+
}
298+
284299
/**
285300
* returns the HTML markup of a fieldset
286301
* @param array $args

includes/class-wcdp-hooks.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,33 @@ public function wcdp_modify_template($template = '', $template_name = '', $args
104104
return $template;
105105
}
106106

107+
$order = null;
108+
if (isset($args['order'])) {
109+
$order = $args['order'];
110+
} else if (isset($args['order_id'])) {
111+
$order = wc_get_order($args['order_id']);
112+
}
107113
$path = WCDP_DIR . 'includes/wc-templates/';
108114
$donable = WCDP_Form::is_donable(get_queried_object_id());
109115

110116
switch ($template_name) {
111117
case 'checkout/review-order.php':
112118
case 'checkout/form-login.php':
113-
case 'checkout/thankyou.php':
114119
case 'checkout/cart-errors.php':
115120
case 'checkout/form-checkout.php':
116-
case 'checkout/order-receipt.php':
117121
case 'checkout/payment.php':
118122
case 'checkout/form-billing.php':
123+
if (
124+
get_option('wcdp_compatibility_mode', 'no') === 'no' &&
125+
WCDP_Form::cart_contains_only_donations()
126+
) {
127+
$template = $path . $template_name;
128+
}
129+
break;
130+
131+
case 'checkout/order-receipt.php':
119132
case 'checkout/order-received.php':
133+
case 'checkout/thankyou.php':
120134

121135
case 'myaccount/dashboard.php':
122136
case 'myaccount/view-order.php':
@@ -152,6 +166,13 @@ public function wcdp_modify_template($template = '', $template_name = '', $args
152166
case 'emails/plain/admin-new-order.php':
153167
case 'emails/plain/admin-failed-order.php':
154168
case 'emails/plain/admin-cancelled-order.php':
169+
if (
170+
get_option('wcdp_compatibility_mode', 'no') === 'no' &&
171+
($order === null || WCDP_Form::order_contains_only_donations($order))
172+
) {
173+
$template = $path . $template_name;
174+
}
175+
break;
155176

156177
case 'loop/no-products-found.php':
157178
if (get_option('wcdp_compatibility_mode', 'no') === 'no') {
@@ -279,9 +300,12 @@ public function wcdp_order_button_html($html)
279300
*
280301
* @return string
281302
*/
282-
public function wcdp_order_button_text(): string
303+
public function wcdp_order_button_text($label): string
283304
{
284-
return __('Donate now', 'wc-donation-platform');
305+
if (WCDP_Form::cart_contains_only_donations(WC()->cart)) {
306+
return __('Donate now', 'wc-donation-platform');
307+
}
308+
return $label;
285309
}
286310

287311
/**

0 commit comments

Comments
 (0)