1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<?php
namespace PaymentPlugins;
defined( 'ABSPATH' ) || exit();
use \PaymentPlugins\WC_Braintree_Constants as Constants;
class WC_Braintree_Admin_Meta_Box_Product_Data {
private static $_gateways = array();
private static $_options = array();
public static function init() {
add_filter( 'woocommerce_product_data_tabs', array( __CLASS__, 'product_data_tabs' ) );
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'output_panel' ) );
add_action( 'woocommerce_admin_process_product_object', array( __CLASS__, 'save' ) );
}
public static function product_data_tabs( $tabs ) {
if ( current_user_can( 'manage_woocommerce' ) ) {
$tabs['braintree'] = array(
'label' => __( 'Braintree Settings', 'woo-payment-gateway' ),
'target' => 'braintree_product_data',
'class' => array( 'hide_if_external' ),
'priority' => 100,
);
}
return $tabs;
}
public static function output_panel() {
global $product_object;
self::init_gateways( $product_object );
if ( current_user_can( 'manage_woocommerce' ) ) {
include 'views/html-product-data.php';
}
}
private static function init_gateways( $product ) {
$order = $product->get_meta( Constants::PRODUCT_GATEWAY_ORDER );
$order = ! $order ? array() : $order;
foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
if ( $gateway->supports( 'wc_braintree_product_checkout' ) ) {
$option = new \WC_Braintree_Product_Gateway_Option( $product, $gateway );
if ( isset( $order[ $gateway->id ] ) ) {
self::$_options[ $order[ $gateway->id ] ] = $option;
} else {
self::$_options[] = $option;
}
}
}
ksort( self::$_options );
}
private static function get_product_option( $gateway_id ) {
return self::$_options[ $gateway_id ];
}
public static function save( $product ) {
if ( empty( $_POST['wc_braintree_update_product'] ) ) {
return;
}
$loop = 0;
$order = array();
self::init_gateways( $product );
if ( isset( $_POST['braintree_gateway_order'] ) ) {
foreach ( $_POST['braintree_gateway_order'] as $i => $gateway ) {
$order[ $gateway ] = $loop;
$loop ++;
}
}
if ( isset( $_POST[ Constants::BUTTON_POSITION ] ) ) {
$product->update_meta_data( Constants::BUTTON_POSITION, wc_clean( $_POST[ Constants::BUTTON_POSITION ] ) );
}
$product->update_meta_data( Constants::PRODUCT_GATEWAY_ORDER, $order );
}
public static function output_option_settings( $option ) {
?>
<script type="text/template" id="tmpl-wc-product-<?php echo $option->get_payment_method()->id ?>">
<div class="wc-backbone-modal">
<div class="wc-backbone-modal-content">
<section class="wc-backbone-modal-main" role="main">
<header class="wc-backbone-modal-header">
<h1><?php printf( __( '%s Settings', 'woo-payment-gateway' ), $option->get_payment_method()->get_method_title() ); ?></h1>
<button
class="modal-close modal-close-link dashicons dashicons-no-alt">
<span class="screen-reader-text">Close modal panel</span>
</button>
</header>
<article>
<
<?php esc_html_e( 'Subscription products don\'t support Pay Later due to regulations, but if enabled, PayPal Credit will show.', 'woo-payment-gateway' ) ?>
<
<?php esc_html_e('Pre-order products don\'t support Pay Later due to regulations, but if enabled, PayPal Credit will show.', 'woo-payment-gateway')?>
<
<form class="wc-braintree-product-form">
<?php $option->admin_options() ?>
</form>
</article>
<footer>
<div class="inner">
<button class="button button-primary button-large btn-save-product-options"><?php esc_html_e( 'Save', 'woo-payment-gateway' ); ?></button>
</div>
</footer>
</section>
</div>
</div>
<div class="wc-backbone-modal-backdrop modal-close"></div>
</script>
<?php
}
}
\PaymentPlugins\WC_Braintree_Admin_Meta_Box_Product_Data::init();