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
<?php
namespace SIW\WooCommerce\Checkout;
use SIW\Elements;
class Terms{
protected $modal_link;
public static function init() {
$self = new self();
add_filter( 'woocommerce_get_terms_and_conditions_checkbox_text', [ $self, 'set_term_checkbox_text'] );
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
add_action( 'woocommerce_checkout_init', [ $self, 'add_terms_modal'] );
add_filter( 'wc_get_template', [ $self, 'set_terms_template'], 10, 5 );
add_action( 'wp_enqueue_scripts', [ $self, 'add_script'] );
}
public function set_term_checkbox_text() {
return sprintf(__( 'Ik heb de %s gelezen en ga akkoord', 'siw' ), $this->modal_link );
}
public function add_terms_modal() {
$terms_page_id = wc_terms_and_conditions_page_id();
$this->modal_link = Elements::generate_page_modal( $terms_page_id, __( 'inschrijfvoorwaarden', 'siw' ) );
}
public function add_script() {
wp_register_script( 'siw-checkout-terms', SIW_ASSETS_URL . 'js/siw-checkout-terms.js', [ 'siw-modal' ], SIW_PLUGIN_VERSION, true );
if ( is_checkout() && ! is_order_received_page() && ! is_checkout_pay_page() ) {
wp_enqueue_script( 'siw-checkout-terms' );
}
}
public function set_terms_template( string $located, string $template_name, array $args, string $template_path, string $default_path ) {
if ( 'checkout/terms.php' === $template_name ) {
$located = SIW_TEMPLATES_DIR . '/woocommerce/'. $template_name;
}
return $located;
}
}