| 1 |
<?php namespace TierPricingTable\Addons\NonLoggedInUsers\CartRules; |
| 2 |
|
| 3 |
use TierPricingTable\Addons\NonLoggedInUsers\Roles; |
| 4 |
use TierPricingTable\Settings\CustomOptions\TPTCheckboxListOption; |
| 5 |
use TierPricingTable\Settings\Sections\SubsectionAbstract; |
| 6 |
|
| 7 |
class PaymentMethodsSubsection extends SubsectionAbstract { |
| 8 |
|
| 9 |
public function getTitle(): string { |
| 10 |
return __( 'Payment methods by role', 'tier-pricing-table' ); |
| 11 |
} |
| 12 |
|
| 13 |
public function getDescription(): string { |
| 14 |
if ( ! $this->getGateways() ) { |
| 15 |
return __( 'No payment method is enabled yet. Enable payment methods under WooCommerce → Settings → Payments, then choose here who may use each.', 'tier-pricing-table' ); |
| 16 |
} |
| 17 |
|
| 18 |
return __( 'Who may use each enabled payment method, for example invoice payment for wholesale customers only. Leave a method empty to keep it available to everyone.', 'tier-pricing-table' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function getSlug(): string { |
| 22 |
return 'payment-methods'; |
| 23 |
} |
| 24 |
|
| 25 |
public function getSettings(): array { |
| 26 |
$settings = array(); |
| 27 |
|
| 28 |
foreach ( $this->getGateways() as $id => $title ) { |
| 29 |
$settings[] = array( |
| 30 |
'title' => $title, |
| 31 |
'id' => CartRulesSettings::optionId( 'gateway_' . sanitize_key( $id ) ), |
| 32 |
'type' => TPTCheckboxListOption::FIELD_TYPE, |
| 33 |
'display' => 'checkboxes', |
| 34 |
'options' => Roles::getOptions(), |
| 35 |
'default' => '', |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
return $settings; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @return array<string, string> gateway id => title, enabled gateways only |
| 44 |
*/ |
| 45 |
protected function getGateways(): array { |
| 46 |
$gateways = array(); |
| 47 |
|
| 48 |
if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways() ) { |
| 49 |
return $gateways; |
| 50 |
} |
| 51 |
|
| 52 |
foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) { |
| 53 |
if ( 'yes' === $gateway->enabled ) { |
| 54 |
$gateways[ (string) $gateway->id ] = wp_strip_all_tags( $gateway->get_method_title() ?: $gateway->get_title() ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $gateways; |
| 59 |
} |
| 60 |
} |
| 61 |
|