<?php
/**
 * Custom WooCommerce Product Type: Subscription
 *
 * @package Invizo\SubscriptionsLite\Integrations
 */

namespace Invizo\SubscriptionsLite\Integrations;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WC_Product_Simple' ) ) {
	return;
}

// Bind the Add to Cart template for our custom product type
add_action( 'woocommerce_invizo_subscription_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );

class WC_Product_Subscription extends \WC_Product_Simple {

    public function get_type() {
        return 'invizo_subscription';
    }

    public function get_price_html( $price = '' ) {
        $price_html = parent::get_price_html( $price );

        $interval_count  = absint( $this->get_meta( '_invizo_sub_interval_count' ) );
        $interval_period = sanitize_text_field( (string) $this->get_meta( '_invizo_sub_interval_period' ) );

        if ( ! empty( $interval_count ) && ! empty( $interval_period ) ) {
            $price_html .= ' / ' . esc_html( (string) $interval_count . ' ' . ucfirst( $interval_period ) );
        }

        return apply_filters( 'invizo_subscription_price_html', $price_html, $this );
    }

    public function add_to_cart_text() {
        return __( 'Sign up now', 'invizo-subscriptions-lite' );
    }

    public function single_add_to_cart_text() {
        return __( 'Sign up now', 'invizo-subscriptions-lite' );
    }
}
