| 1 |
<?php |
| 2 |
|
| 3 |
namespace TierPricingTable\Integrations\Plugins\Elementor; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Widget_Base; |
| 7 |
use TierPricingTable\Core\ServiceContainer; |
| 8 |
use TierPricingTable\PricingTable; |
| 9 |
class ElementorWidget extends Widget_Base { |
| 10 |
public function get_name() : string { |
| 11 |
return 'tiered-pricing-table'; |
| 12 |
} |
| 13 |
|
| 14 |
public function get_title() : string { |
| 15 |
return esc_html__( 'Tiered Pricing Table', 'tier-pricing-table' ); |
| 16 |
} |
| 17 |
|
| 18 |
public function get_icon() : string { |
| 19 |
return 'eicon-price-table'; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_custom_help_url() : string { |
| 23 |
return 'https://u2code.com/plugins/tiered-pricing-table-for-woocommerce/'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_categories() : array { |
| 27 |
return array('woocommerce', 'general'); |
| 28 |
} |
| 29 |
|
| 30 |
public function get_keywords() : array { |
| 31 |
return array('tiered', 'table', 'pricing'); |
| 32 |
} |
| 33 |
|
| 34 |
protected function register_controls() { |
| 35 |
$this->start_controls_section( 'content_section', [ |
| 36 |
'label' => esc_html__( 'Main', 'tier-pricing-table' ), |
| 37 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 38 |
] ); |
| 39 |
$this->add_control( 'product_id', [ |
| 40 |
'label' => __( 'Product ID', 'tier-pricing-table' ), |
| 41 |
'type' => Controls_Manager::NUMBER, |
| 42 |
'label_block' => true, |
| 43 |
'description' => __( 'Leave empty to use the current product.', 'tier-pricing-table' ), |
| 44 |
] ); |
| 45 |
$this->add_control( 'display_type', [ |
| 46 |
'label' => __( 'Display type', 'tier-pricing-table' ), |
| 47 |
'type' => Controls_Manager::SELECT, |
| 48 |
'default' => 'table', |
| 49 |
'options' => [ |
| 50 |
'table' => esc_html__( 'Table', 'tier-pricing-table' ), |
| 51 |
'blocks' => esc_html__( 'Blocks', 'tier-pricing-table' ), |
| 52 |
'options' => esc_html__( 'Options', 'tier-pricing-table' ), |
| 53 |
'dropdown' => esc_html__( 'Dropdown', 'tier-pricing-table' ), |
| 54 |
'horizontal-table' => esc_html__( 'Horizontal-table', 'tier-pricing-table' ), |
| 55 |
], |
| 56 |
'label_block' => true, |
| 57 |
] ); |
| 58 |
$this->add_control( 'title', [ |
| 59 |
'label' => __( 'Title', 'tier-pricing-table' ), |
| 60 |
'type' => Controls_Manager::TEXT, |
| 61 |
'label_block' => true, |
| 62 |
'description' => __( 'Tiered pricing title. Leave empty to use default title.', 'tier-pricing-table' ), |
| 63 |
] ); |
| 64 |
$this->add_control( 'options_show_original_product_price', [ |
| 65 |
'label' => __( 'Show prices without a discount', 'tier-pricing-table' ), |
| 66 |
'type' => Controls_Manager::SWITCHER, |
| 67 |
'label_block' => true, |
| 68 |
'default' => 'yes', |
| 69 |
'description' => __( 'Show price with no discount in the option.', 'tier-pricing-table' ), |
| 70 |
'condition' => [ |
| 71 |
'display_type' => ['options', 'dropdown'], |
| 72 |
], |
| 73 |
] ); |
| 74 |
$this->add_control( 'options_show_default_option', [ |
| 75 |
'label' => __( 'Show the default option', 'tier-pricing-table' ), |
| 76 |
'type' => Controls_Manager::SWITCHER, |
| 77 |
'label_block' => true, |
| 78 |
'default' => 'yes', |
| 79 |
'description' => __( 'Show the option without a discount (option with a regular product price)', 'tier-pricing-table' ), |
| 80 |
'condition' => [ |
| 81 |
'display_type' => ['options', 'dropdown'], |
| 82 |
], |
| 83 |
] ); |
| 84 |
$this->add_control( 'active_tier_color', [ |
| 85 |
'label' => __( 'Active tier color', 'tier-pricing-table' ), |
| 86 |
'type' => Controls_Manager::COLOR, |
| 87 |
'label_block' => true, |
| 88 |
'description' => __( 'Leave empty to use the default color.', 'tier-pricing-table' ), |
| 89 |
] ); |
| 90 |
$this->add_control( 'quantity_column_title', [ |
| 91 |
'label' => __( 'Quantity column text', 'tier-pricing-table' ), |
| 92 |
'type' => Controls_Manager::TEXT, |
| 93 |
'label_block' => true, |
| 94 |
'description' => __( 'Leave empty to use default title.', 'tier-pricing-table' ), |
| 95 |
'condition' => [ |
| 96 |
'display_type' => 'table', |
| 97 |
], |
| 98 |
] ); |
| 99 |
$this->add_control( 'discount_column_title', [ |
| 100 |
'label' => __( 'Discount column text', 'tier-pricing-table' ), |
| 101 |
'type' => Controls_Manager::TEXT, |
| 102 |
'label_block' => true, |
| 103 |
'description' => __( 'Leave empty to use default title.', 'tier-pricing-table' ), |
| 104 |
'condition' => [ |
| 105 |
'display_type' => 'table', |
| 106 |
], |
| 107 |
] ); |
| 108 |
$this->add_control( 'price_column_title', [ |
| 109 |
'label' => __( 'Price column text', 'tier-pricing-table' ), |
| 110 |
'type' => Controls_Manager::TEXT, |
| 111 |
'label_block' => true, |
| 112 |
'description' => __( 'Leave empty to use default title.', 'tier-pricing-table' ), |
| 113 |
'condition' => [ |
| 114 |
'display_type' => 'table', |
| 115 |
], |
| 116 |
] ); |
| 117 |
$quantity_measurement = ServiceContainer::getInstance()->getSettings()->get( 'table_quantity_measurement', array( |
| 118 |
'singular' => '', |
| 119 |
'plural' => '', |
| 120 |
) ); |
| 121 |
$this->add_control( 'quantity_measurement_singular', [ |
| 122 |
'label' => __( 'Unit label (singular)', 'tier-pricing-table' ), |
| 123 |
'type' => Controls_Manager::TEXT, |
| 124 |
'label_block' => true, |
| 125 |
'description' => __( 'Leave empty to use default', 'tier-pricing-table' ), |
| 126 |
'condition' => [ |
| 127 |
'display_type' => ['table', 'blocks'], |
| 128 |
], |
| 129 |
'default' => $quantity_measurement['singular'], |
| 130 |
] ); |
| 131 |
$this->add_control( 'quantity_measurement_plural', [ |
| 132 |
'label' => __( 'Unit label (plural)', 'tier-pricing-table' ), |
| 133 |
'type' => Controls_Manager::TEXT, |
| 134 |
'label_block' => true, |
| 135 |
'description' => __( 'Leave empty to use default', 'tier-pricing-table' ), |
| 136 |
'condition' => [ |
| 137 |
'display_type' => ['table', 'blocks'], |
| 138 |
], |
| 139 |
'default' => $quantity_measurement['plural'], |
| 140 |
] ); |
| 141 |
$this->end_controls_section(); |
| 142 |
} |
| 143 |
|
| 144 |
protected function render() { |
| 145 |
$settings = $this->get_settings_for_display(); |
| 146 |
$args = array(); |
| 147 |
if ( isset( $settings['display_type'] ) ) { |
| 148 |
$args['display_type'] = $settings['display_type']; |
| 149 |
} |
| 150 |
if ( isset( $settings['title'] ) ) { |
| 151 |
$args['title'] = $settings['title']; |
| 152 |
} |
| 153 |
if ( !empty( $settings['active_tier_color'] ) ) { |
| 154 |
$args['active_tier_color'] = $settings['active_tier_color']; |
| 155 |
} |
| 156 |
if ( !empty( $settings['price_column_title'] ) ) { |
| 157 |
$args['price_column_title'] = $settings['price_column_title']; |
| 158 |
} |
| 159 |
if ( !empty( $settings['discount_column_title'] ) ) { |
| 160 |
$args['discount_column_title'] = $settings['discount_column_title']; |
| 161 |
} |
| 162 |
if ( !empty( $settings['quantity_column_title'] ) ) { |
| 163 |
$args['quantity_column_title'] = $settings['quantity_column_title']; |
| 164 |
} |
| 165 |
if ( isset( $settings['quantity_measurement_singular'] ) ) { |
| 166 |
$args['quantity_measurement_singular'] = $settings['quantity_measurement_singular']; |
| 167 |
} |
| 168 |
if ( isset( $settings['quantity_measurement_plural'] ) ) { |
| 169 |
$args['quantity_measurement_plural'] = $settings['quantity_measurement_plural']; |
| 170 |
} |
| 171 |
if ( isset( $settings['options_show_total'] ) ) { |
| 172 |
$args['options_show_total'] = 'yes' === $settings['options_show_total']; |
| 173 |
} else { |
| 174 |
$args['options_show_total'] = false; |
| 175 |
} |
| 176 |
if ( isset( $settings['options_show_original_product_price'] ) ) { |
| 177 |
$args['options_show_original_product_price'] = 'yes' === $settings['options_show_original_product_price']; |
| 178 |
} else { |
| 179 |
$args['options_show_original_product_price'] = false; |
| 180 |
} |
| 181 |
if ( isset( $settings['options_show_default_option'] ) ) { |
| 182 |
$args['options_show_default_option'] = 'yes' === $settings['options_show_default_option']; |
| 183 |
} else { |
| 184 |
$args['options_show_default_option'] = false; |
| 185 |
} |
| 186 |
if ( $settings['product_id'] ) { |
| 187 |
$productId = intval( $settings['product_id'] ); |
| 188 |
} else { |
| 189 |
global $post; |
| 190 |
if ( !$post ) { |
| 191 |
return; |
| 192 |
} |
| 193 |
$productId = $post->ID; |
| 194 |
} |
| 195 |
$args['display'] = true; |
| 196 |
PricingTable::getInstance()->renderPricingTable( $productId, null, $args ); |
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
|