# tier-pricing-table/8.0.2/src/Settings/CustomOptions/TPTLinkButton.php

Tiered Pricing Table for WooCommerce, version 8.0.2. 43 lines.

- Page: https://pluginprobe.com/plugins/tier-pricing-table/8.0.2/code/src/Settings/CustomOptions/TPTLinkButton.php
- Raw: https://pluginprobe.com/plugins/tier-pricing-table/8.0.2/raw/src/Settings/CustomOptions/TPTLinkButton.php
- Modified: 2023-11-06T14:03:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tier-pricing-table/8.0.2/code/src/Settings/CustomOptions/TPTLinkButton.php#L10-L20`.

```php
<?php namespace TierPricingTable\Settings\CustomOptions;

class TPTLinkButton {

	const FIELD_TYPE = 'tpt_link_button';

	public function __construct() {
		add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );

		add_action( 'woocommerce_admin_settings_sanitize_option', function ( $value, $option, $rawValue ) {

			if ( self::FIELD_TYPE === $option['type'] ) {
				$value = in_array( $value, array( 1, 'yes' ) ) ? 'yes' : 'no';
			}

			return $value;
		}, 10, 3 );
	}

	public function render( $value ) {
		if ( ! isset( $value['id'] ) ) {
			$value['id'] = '';
		}

		if ( ! isset( $value['title'] ) ) {
			$value['title'] = isset( $value['name'] ) ? $value['name'] : '';
		}

		?>
		<tr valign="top">
			<th scope="row" class="titledesc">
				<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
			</th>
			<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
				<a href="<?php echo esc_attr( $value['button_link'] ); ?>"
				   class="<?php echo esc_attr( $value['button_class'] ); ?>">
					<?php echo esc_html( $value['button_text'] ); ?>
				</a>
			</td>
		</tr>
		<?php
	}
}
```
