<?php

class WCML_Url_Filters_Redirect_Location {
	private $wpml_url_converter;

	public function __construct( WPML_URL_Converter $wpml_url_converter ) {
		$this->wpml_url_converter = $wpml_url_converter;
	}

	public function add_hooks() {
		$hooks = [ 'woocommerce_get_checkout_payment_url', 'woocommerce_get_cancel_order_url', 'woocommerce_get_return_url' ];

		foreach ( $hooks as $hook ) {
			add_filter( $hook, [ $this, 'filter' ], 10, 1 );
		}
	}

	public function filter( $link ) {
		return html_entity_decode( $this->wpml_url_converter->convert_url( $link ) );
	}
}
