PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / NonLoggedInUsers / CartRules / PaymentMethodsSubsection.php

PaymentMethodsSubsection.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/CartRules/PaymentMethodsSubsection.php

61 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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