PPV and discount for premium members on PPVs

parent b5c7d0aa
...@@ -30,11 +30,18 @@ function wcpms_adminpage() ...@@ -30,11 +30,18 @@ function wcpms_adminpage()
sh_get_template('admin/wcpms.php'); sh_get_template('admin/wcpms.php');
} }
function settings_wcpms_section() function settings_wcpms_section()
{ {
echo "<h2>SexHackMe PMS - WooCommerce integration Settings</h2>"; echo "<h2>SexHackMe PMS - WooCommerce integration Settings</h2>";
} }
function settings_wcpms_section_premium_discount()
{
echo "<h2>Premium users discount on Videos</h2>";
}
function settings_wcpms_section_email() function settings_wcpms_section_email()
{ {
echo "<h2>WooCommerce Checkout Email endpoint</h2>"; echo "<h2>WooCommerce Checkout Email endpoint</h2>";
......
...@@ -61,6 +61,7 @@ if(!class_exists('SH_Admin')) { ...@@ -61,6 +61,7 @@ if(!class_exists('SH_Admin')) {
add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section_prodcat', 'sexhackme-wcpms-settings-prodcat'); add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section_prodcat', 'sexhackme-wcpms-settings-prodcat');
register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodcat'); register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodcat');
register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodvisible'); register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodvisible');
register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms_premium_discount');
} }
......
...@@ -51,6 +51,7 @@ if(!class_exists('SH_Video')) { ...@@ -51,6 +51,7 @@ if(!class_exists('SH_Video')) {
'hls_public' => false, 'hls_public' => false,
'hls_members' => false, 'hls_members' => false,
'hls_premium' => false, 'hls_premium' => false,
'premium_is_ppv' => 'N',
'thumbnail' => false, 'thumbnail' => false,
'gif' => false, 'gif' => false,
'gif_small' => false, 'gif_small' => false,
......
...@@ -116,6 +116,7 @@ if(!class_exists('SH_VideoGallery')) { ...@@ -116,6 +116,7 @@ if(!class_exists('SH_VideoGallery')) {
$hls_premium = $video->hls_premium; $hls_premium = $video->hls_premium;
$video_preview = $video->preview; $video_preview = $video->preview;
$gif_preview = $video->gif_small; $gif_preview = $video->gif_small;
$premium_is_ppv = $video->premium_is_ppv;
//sexhack_log($video); //sexhack_log($video);
...@@ -140,7 +141,10 @@ if(!class_exists('SH_VideoGallery')) { ...@@ -140,7 +141,10 @@ if(!class_exists('SH_VideoGallery')) {
if($hls_public) $vtags[] = '<label class="sexhack_vtag sexhack_public" style="*LEFT*">public</label>'; if($hls_public) $vtags[] = '<label class="sexhack_vtag sexhack_public" style="*LEFT*">public</label>';
elseif($video_preview) $vtags[] = '<label class="sexhack_vtag sexhack_preview" style="*LEFT*">preview</label>'; elseif($video_preview) $vtags[] = '<label class="sexhack_vtag sexhack_preview" style="*LEFT*">preview</label>';
if($hls_member)$vtags[] = '<label class="sexhack_vtag sexhack_members" style="*LEFT*">members</label>'; if($hls_member)$vtags[] = '<label class="sexhack_vtag sexhack_members" style="*LEFT*">members</label>';
if($hls_premium)$vtags[] = '<label class="sexhack_vtag sexhack_premium" style="*LEFT*">premium</label>'; if($hls_premium) {
if($video->ppv_is_ppv) $vtags[] = '<label class="sexhack_vtag sexhack_premium" style="*LEFT*">PPV</label>';
else $vtags[] = '<label class="sexhack_vtag sexhack_premium" style="*LEFT*">premium</label>';
}
if($video->has_downloads()) $html .= '<label class="sexhack_vtag sexhack_download"">download</label>'; if($video->has_downloads()) $html .= '<label class="sexhack_vtag sexhack_download"">download</label>';
if($video->video_type == 'VR') $html .= '<label class="sexhack_vtag sexhack_VR"">VR/3D</label>'; if($video->video_type == 'VR') $html .= '<label class="sexhack_vtag sexhack_VR"">VR/3D</label>';
......
...@@ -86,7 +86,7 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -86,7 +86,7 @@ if(!class_exists("SH_VideoProducts")) {
$prod->set_slug($video->slug); $prod->set_slug($video->slug);
// Product description. // Product description.
$video_link=site_url().'/'.get_option('gallery_slug', 'v')."/".$video->slug."/"; $video_link=site_url().'/'.get_option('gallery_slug', 'v')."/".$video->slug."/";
$prod->set_short_description('<p>Whach me <a href="'.$video_link.'">ONLINE HERE</a></p>'); $prod->set_short_description('<p>Whach me <a href="'.$video_link.'">ONLINE HERE</a></p>');
$prod->set_description($video->description); $prod->set_description($video->description);
...@@ -112,19 +112,19 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -112,19 +112,19 @@ if(!class_exists("SH_VideoProducts")) {
// Price // Price
$prod->set_regular_price(floatval($video->price)); $prod->set_regular_price(floatval($video->price));
// Prepare product attributes // Prepare product attributes
$attrs = array(); $attrs = array();
// Videw Preview // Videw Preview
$attribute = new \WC_Product_Attribute(); $attribute = new \WC_Product_Attribute();
$attribute->set_name( 'video_preview' ); $attribute->set_name( 'video_preview' );
$attribute->set_options( array($video->preview) ); $attribute->set_options( array($video->preview) );
$attribute->set_visible( false ); $attribute->set_visible( false );
$attribute->set_variation( false ); $attribute->set_variation( false );
$attrs[] = $attribute; $attrs[] = $attribute;
$prod->set_attributes($attrs); $prod->set_attributes($attrs);
// Download links // Download links
$download_public = apply_filters('sh_download_url_filter', $video->download_public); $download_public = apply_filters('sh_download_url_filter', $video->download_public);
...@@ -139,7 +139,7 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -139,7 +139,7 @@ if(!class_exists("SH_VideoProducts")) {
$wcdownload->set_name(basename($video->download_public)); // XXX Do we really want to use basename here? $wcdownload->set_name(basename($video->download_public)); // XXX Do we really want to use basename here?
$wcdownload->set_id( md5( $download_public )); $wcdownload->set_id( md5( $download_public ));
$wcdownload->set_file( $download_public ); $wcdownload->set_file( $download_public );
$wcdowns[] = $wcdownload; $wcdowns[] = $wcdownload;
} }
if($download_members) if($download_members)
...@@ -148,7 +148,7 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -148,7 +148,7 @@ if(!class_exists("SH_VideoProducts")) {
$wcdownload->set_name(basename($video->download_members)); // XXX Do we really want to use basename here? $wcdownload->set_name(basename($video->download_members)); // XXX Do we really want to use basename here?
$wcdownload->set_id( md5( $download_members )); $wcdownload->set_id( md5( $download_members ));
$wcdownload->set_file( $download_members ); $wcdownload->set_file( $download_members );
$wcdowns[] = $wcdownload; $wcdowns[] = $wcdownload;
} }
if($download_premium) if($download_premium)
...@@ -160,7 +160,7 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -160,7 +160,7 @@ if(!class_exists("SH_VideoProducts")) {
$wcdowns[] = $wcdownload; $wcdowns[] = $wcdownload;
} }
$prod->set_downloads( $wcdowns ); $prod->set_downloads( $wcdowns );
// Categories. // Categories.
...@@ -197,12 +197,12 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -197,12 +197,12 @@ if(!class_exists("SH_VideoProducts")) {
} }
// Save the product // Save the product
$prod->save(); $prod->save();
$video->product_id = $prod->get_id(); $video->product_id = $prod->get_id();
//sexhack_log($video); //sexhack_log($video);
return $video; return $video;
} }
} }
...@@ -210,6 +210,110 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -210,6 +210,110 @@ if(!class_exists("SH_VideoProducts")) {
} }
/* Discount for premium members on PPVs */
if(!class_exists('SexhackDiscount')) {
class SexhackDiscount
{
public function __construct()
{
//add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_user_role', 20, 1 );
add_filter( 'woocommerce_get_price_html', array($this, 'custom_price_display_premium'), 9999, 2 );
add_action( 'woocommerce_before_calculate_totals', array($this, 'custom_price_cart_premium'), 9999 );
}
public function custom_price_display_premium($price_html, $product)
{
if ( is_admin() || empty( $product->get_price() ) ) return $price_html;
if(!user_has_premium_access()) return $price_html;
$product_id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
$discount = $this->check_discount_premium( $product_id );
if ( $discount['apply'] ) {
if ( $product->get_type() == 'variable' ) {
$price_html = sprintf( '%s - %s', wc_price( $product->get_variation_regular_price( 'min' ) * $discount['percentage'] ),
wc_price( $product->get_variation_regular_price( 'max' ) * $discount['percentage'] ));
} else {
$price_html = wc_price( $product->get_regular_price() * $discount['percentage'] );
}
}
return $price_html;
}
public function custom_price_cart_premium( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return;
if(!user_has_premium_access()) return;
// Apply discount to cart
foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$product_id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
$discount = $this->check_discount_premium( $product_id );
if ( $discount['apply'] ) {
$cart_item['data']->set_price( $product->get_regular_price() * $discount['percentage'] );
}
}
}
public function check_discount_premium( $product_id ) {
$premium_discount = intval(get_option('sexhack_wcpms_premium_discount', '0'));
if($premium_discount > 100 || $premium_discount < 0) $premium_discount = 0;
$discount = array(
'apply' => false,
'precentage' => floatval((100-$premium_discount)/100)
);
$video = sh_get_video_from_product($product_id);
if($video->premium_is_ppv=='Y') $discount['apply'] = true;
/*
// Get all product categories for the current product
$terms = wp_get_post_terms( $product_id, 'product_cat' );
foreach ( $terms as $term ) {
$product_categories[] = $term->slug;
}
// Check for discounted categories
if ( !empty( $product_categories ) ) {
// Get array of category matches
$cat_matches = array_intersect( $discount['categories'], $product_categories );
if ( count( $cat_matches ) > 0 ) {
// 1 or more matches
$discount['apply'] = true;
}
} */
return $discount;
}
//public function discount_based_on_user_role( $cart )
//{
/*
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( ! current_user_can('company') )
return;
$percentage = 10;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
// Applying discount
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
*/
//}
}
new SexhackDiscount;
}
/* Class woocommerce add-to-checkout management */ /* Class woocommerce add-to-checkout management */
if(!class_exists('SexhackWoocommerceCheckout')) { if(!class_exists('SexhackWoocommerceCheckout')) {
...@@ -218,7 +322,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) { ...@@ -218,7 +322,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) {
public function __construct() public function __construct()
{ {
//add_action( 'woocommerce_before_checkout_form', array($this, 'empty_cart'), 1); //add_action( 'woocommerce_before_checkout_form', array($this, 'empty_cart'), 1);
add_action( 'woocommerce_add_to_cart_validation', array($this, 'empty_cart'), 1); add_action( 'woocommerce_add_to_cart_validation', array($this, 'empty_cart'), 1);
add_filter( 'woocommerce_add_to_cart_redirect', array($this, 'redirect_checkout_add_cart' )); add_filter( 'woocommerce_add_to_cart_redirect', array($this, 'redirect_checkout_add_cart' ));
...@@ -234,7 +338,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) { ...@@ -234,7 +338,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) {
if(isset($_GET['shm_direct_checkout']) && is_numeric($_GET['shm_direct_checkout'])) { if(isset($_GET['shm_direct_checkout']) && is_numeric($_GET['shm_direct_checkout'])) {
global $woocommerce; global $woocommerce;
$woocommerce->cart->empty_cart(); $woocommerce->cart->empty_cart();
//WC()->session->set('cart', array()); //WC()->session->set('cart', array());
$woocommerce->cart->add_to_cart(intval($_GET['shm_direct_checkout']), 1); $woocommerce->cart->add_to_cart(intval($_GET['shm_direct_checkout']), 1);
} else { } else {
//$woocommerce->cart->empty_cart(); //$woocommerce->cart->empty_cart();
...@@ -257,12 +361,12 @@ if(!class_exists('SexhackWoocommerceCheckout')) { ...@@ -257,12 +361,12 @@ if(!class_exists('SexhackWoocommerceCheckout')) {
} }
public function product_loop_oneclick() { public function product_loop_oneclick() {
global $product; global $product;
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
if(!$product->is_type('variable')) { if(!$product->is_type('variable')) {
echo '<div class="custom-add-to-cart">'; echo '<div class="custom-add-to-cart">';
//woocommerce_template_loop_add_to_cart(); //woocommerce_template_loop_add_to_cart();
echo '<a class="button" href="'.wc_get_checkout_url()."?add-to-cart=".$product->get_id()."&shm_direct_checkout=".$product->get_id().'">Buy now!</a>'; echo '<a class="button" href="'.wc_get_checkout_url()."?add-to-cart=".$product->get_id()."&shm_direct_checkout=".$product->get_id().'">Buy now!</a>';
echo '</div>'; echo '</div>';
} }
} }
...@@ -270,7 +374,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) { ...@@ -270,7 +374,7 @@ if(!class_exists('SexhackWoocommerceCheckout')) {
public function oneclick_checkout() { public function oneclick_checkout() {
global $product; global $product;
echo '<a class="button" href="'.wc_get_checkout_url()."?add-to-cart=".$product->get_id()."&shm_direct_checkout=".$product->get_id().'">Buy now!</a>'; echo '<a class="button" href="'.wc_get_checkout_url()."?add-to-cart=".$product->get_id()."&shm_direct_checkout=".$product->get_id().'">Buy now!</a>';
remove_action('woocommerce_'.$product->get_type().'_add_to_cart', 'woocommerce_'.$product->get_type().'_add_to_cart', 30); remove_action('woocommerce_'.$product->get_type().'_add_to_cart', 'woocommerce_'.$product->get_type().'_add_to_cart', 30);
} }
...@@ -601,11 +705,11 @@ if(!class_exists('SH_WooCommerce_Registration_Integration')) { ...@@ -601,11 +705,11 @@ if(!class_exists('SH_WooCommerce_Registration_Integration')) {
if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) { if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) {
add_filter( 'woocommerce_payment_gateways', 'wp_SexHackMe\sh_add_payment_gateway_class' ); add_filter( 'woocommerce_payment_gateways', 'wp_SexHackMe\sh_add_payment_gateway_class' );
function sh_add_payment_gateway_class( $gateways ) { function sh_add_payment_gateway_class( $gateways ) {
$gateways[] = 'wp_SexHackMe\SH_WooCommerce_Chaturbate_Payments'; // your class name is here $gateways[] = 'wp_SexHackMe\SH_WooCommerce_Chaturbate_Payments'; // your class name is here
return $gateways; return $gateways;
} }
add_action( 'plugins_loaded', 'wp_SexHackMe\chaturbate_payment_init' ); add_action( 'plugins_loaded', 'wp_SexHackMe\chaturbate_payment_init' );
function chaturbate_payment_init() { function chaturbate_payment_init() {
...@@ -616,32 +720,32 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) { ...@@ -616,32 +720,32 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) {
$this->id = 'shchaturbate'; $this->id = 'shchaturbate';
$this->method_title = 'Chaturbate Payment Gateway (SexHackMe)'; $this->method_title = 'Chaturbate Payment Gateway (SexHackMe)';
$this->method_description = 'Receive payments in chaturbate.com tokens'; $this->method_description = 'Receive payments in chaturbate.com tokens';
$this->icon = SH_PLUGIN_DIR_URL.'/img/chaturbate_ico.png'; // URL to the icon $this->icon = SH_PLUGIN_DIR_URL.'/img/chaturbate_ico.png'; // URL to the icon
$this->has_fields = true; $this->has_fields = true;
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
$this->supports = array( $this->supports = array(
'products' 'products'
); );
$this->enabled = $this->get_option( 'enabled' ); $this->enabled = $this->get_option( 'enabled' );
$this->title = $this->get_option('title'); $this->title = $this->get_option('title');
$this->description = $this->get_option('description'); $this->description = $this->get_option('description');
$this->uuid_prefix = $this->get_option('uuid_prefix'); $this->uuid_prefix = $this->get_option('uuid_prefix');
$this->cb_model = $this->get_option('cb_model'); $this->cb_model = $this->get_option('cb_model');
$this->cb_change = $this->get_option('cb_change'); $this->cb_change = $this->get_option('cb_change');
$this->instructions = $this->get_option('instructions'); $this->instructions = $this->get_option('instructions');
$this->api_passkey = $this->get_option('api_passkey'); $this->api_passkey = $this->get_option('api_passkey');
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_action( 'woocommerce_api_shchaturbate', array( $this, 'webhook_cb' ) ); add_action( 'woocommerce_api_shchaturbate', array( $this, 'webhook_cb' ) );
//add_action( 'woocommerce_before_thankyou', array( $this, 'thankyou_page' )); //add_action( 'woocommerce_before_thankyou', array( $this, 'thankyou_page' ));
add_filter('woocommerce_thankyou_order_received_text', array( $this, 'thankyou_page' ), 90, 2); add_filter('woocommerce_thankyou_order_received_text', array( $this, 'thankyou_page' ), 90, 2);
// Customer Emails. // Customer Emails.
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
//add_action( 'woocommerce_order_status_pending', array( $this, 'email_instructions' ), 9000, 2 ); //add_action( 'woocommerce_order_status_pending', array( $this, 'email_instructions' ), 9000, 2 );
...@@ -673,19 +777,19 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) { ...@@ -673,19 +777,19 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) {
} }
} }
die(); die();
//$order->reduce_order_stock(); //$order->reduce_order_stock();
} }
// Initialize settings fields // Initialize settings fields
public function init_form_fields() { public function init_form_fields() {
$this->form_fields = array( $this->form_fields = array(
'enabled' => array( 'enabled' => array(
'title' => 'Enable/Disable', 'title' => 'Enable/Disable',
'label' => 'Enable Chaturbate Gateway', 'label' => 'Enable Chaturbate Gateway',
'type' => 'checkbox', 'type' => 'checkbox',
'description' => '', 'description' => '',
'default' => 'no' 'default' => 'no'
), ),
'title' => array( 'title' => array(
'title' => __('Title', 'woocommerce'), 'title' => __('Title', 'woocommerce'),
'type' => 'text', 'type' => 'text',
...@@ -700,34 +804,34 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) { ...@@ -700,34 +804,34 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) {
'default' => __('Pay using Chaturbate tokens', 'woocommerce'), 'default' => __('Pay using Chaturbate tokens', 'woocommerce'),
'desc_tip' => true, 'desc_tip' => true,
), ),
'cb_change' => array( 'cb_change' => array(
'title' => 'CB Tokens USD conversion', 'title' => 'CB Tokens USD conversion',
'type' => 'number', 'type' => 'number',
'custom_attributes' => array( 'step' => 'any', 'min' => '0' ), 'custom_attributes' => array( 'step' => 'any', 'min' => '0' ),
'description' => 'Value of 1 chaturbate token in USD', 'description' => 'Value of 1 chaturbate token in USD',
'desc_tip' => true, 'desc_tip' => true,
'default' => 0.05, 'default' => 0.05,
), ),
'instructions' => array( 'instructions' => array(
'title' => __( 'Instructions', 'woocommerce' ), 'title' => __( 'Instructions', 'woocommerce' ),
'type' => 'textarea', 'type' => 'textarea',
'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ), 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
'default' => 'Send {TOTAL} chaturbate tokens to https://chaturbate.com/{CB_MODEL} with the message {ORDER_UUID}', 'default' => 'Send {TOTAL} chaturbate tokens to https://chaturbate.com/{CB_MODEL} with the message {ORDER_UUID}',
'desc_tip' => true, 'desc_tip' => true,
), ),
'uuid_prefix' => array( 'uuid_prefix' => array(
'title' => 'Order ID Prefix', 'title' => 'Order ID Prefix',
'type' => 'text', 'type' => 'text',
'description' => 'order ID prefix for messages included in tokens sent', 'description' => 'order ID prefix for messages included in tokens sent',
'desc_tip' => true, 'desc_tip' => true,
'default' => 'SHMPAY-', 'default' => 'SHMPAY-',
), ),
'cb_model' => array( 'cb_model' => array(
'title' => 'Model name', 'title' => 'Model name',
'type' => 'text', 'type' => 'text',
'description' => 'Model name on chaturbate that will receive tokens', 'description' => 'Model name on chaturbate that will receive tokens',
'desc_tip' => true, 'desc_tip' => true,
'default' => 'sexhackme', 'default' => 'sexhackme',
), ),
'api_passkey' => array( 'api_passkey' => array(
'title' => 'API Passkey', 'title' => 'API Passkey',
...@@ -740,83 +844,83 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) { ...@@ -740,83 +844,83 @@ if(!class_exists('SH_WooCommerce_Chaturbate_Payments')) {
); );
} }
private function print_instructions($order_id, $totalusd=-1) private function print_instructions($order_id, $totalusd=-1)
{ {
$instr = str_replace('{CB_MODEL}', $this->cb_model, $this->instructions ); $instr = str_replace('{CB_MODEL}', $this->cb_model, $this->instructions );
$instr = str_replace('{ORDER_UUID}', $this->uuid_prefix.strval($order_id), $instr); $instr = str_replace('{ORDER_UUID}', $this->uuid_prefix.strval($order_id), $instr);
if($totalusd < 0) { if($totalusd < 0) {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
$totalusd = $order->get_total(); $totalusd = $order->get_total();
} }
$instr = str_replace('{TOTAL}', intval($this->usd2tokens($totalusd)), $instr); $instr = str_replace('{TOTAL}', intval($this->usd2tokens($totalusd)), $instr);
return $instr; return $instr;
} }
//public function thankyou_page($order_id) { //public function thankyou_page($order_id) {
public function thankyou_page($msg, $order) { public function thankyou_page($msg, $order) {
$order_id=$order->get_id(); $order_id=$order->get_id();
if ( $this->instructions ) { if ( $this->instructions ) {
//$order = wc_get_order( $order_id ); //$order = wc_get_order( $order_id );
if($order->get_payment_method() == 'shchaturbate') if($order->get_payment_method() == 'shchaturbate')
return "Thank you, we received your order!\n".wp_kses_post( wpautop( wptexturize( $this->print_instructions($order_id, $order->get_total()) ) ) ); return "Thank you, we received your order!\n".wp_kses_post( wpautop( wptexturize( $this->print_instructions($order_id, $order->get_total()) ) ) );
//echo wp_kses_post( wpautop( wptexturize( $this->print_instructions($order_id, $order->get_total()) ) ) ); //echo wp_kses_post( wpautop( wptexturize( $this->print_instructions($order_id, $order->get_total()) ) ) );
} }
return $msg; return $msg;
} }
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && if ( $this->instructions && ! $sent_to_admin &&
'shchaturbate' === $order->get_payment_method() && 'shchaturbate' === $order->get_payment_method() &&
$order->has_status( apply_filters( 'woocommerce_shchaturbate_email_instructions_order_status', 'on-hold', $order ) ) ) { $order->has_status( apply_filters( 'woocommerce_shchaturbate_email_instructions_order_status', 'on-hold', $order ) ) ) {
$note=wp_kses_post( wpautop( wptexturize( $this->print_instructions($order->get_id(), $order->get_total()) ) ) . PHP_EOL ); $note=wp_kses_post( wpautop( wptexturize( $this->print_instructions($order->get_id(), $order->get_total()) ) ) . PHP_EOL );
echo $note; echo $note;
$order->update_status('pending', $note); $order->update_status('pending', $note);
} }
} }
// Process payment // Process payment
public function process_payment($order_id) { public function process_payment($order_id) {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
$total = $order->get_total(); $total = $order->get_total();
if ( $total > 0 ) { if ( $total > 0 ) {
// Mark as on-hold (we're awaiting the shchaturbate). // Mark as on-hold (we're awaiting the shchaturbate).
$order->update_status( $order->update_status(
apply_filters( 'woocommerce_shchaturbate_process_payment_order_status', 'on-hold', $order ), apply_filters( 'woocommerce_shchaturbate_process_payment_order_status', 'on-hold', $order ),
'Waiting for '.intval($this->usd2tokens($total)).' tokens to https://chaturbate.com/'.$this->cb_model.' with message '.$this->uuid_prefix.$order_id 'Waiting for '.intval($this->usd2tokens($total)).' tokens to https://chaturbate.com/'.$this->cb_model.' with message '.$this->uuid_prefix.$order_id
); );
} else { } else {
$order->payment_complete(); $order->payment_complete();
} }
// if($total<-0) // if($total<-0)
// $order->payment_complete(); // $order->payment_complete();
//$order->update_status('on-hold', __( 'Pay by sending '.intval($total/0.05).' tokens to https://chaturbate.com/sexhackme', 'woocommerce' )); //$order->update_status('on-hold', __( 'Pay by sending '.intval($total/0.05).' tokens to https://chaturbate.com/sexhackme', 'woocommerce' ));
/* /*
$order->add_order_note( $order->add_order_note(
'Please go on https://chaturbate.com/sexhackme and tip '.intval($total/0.05).' tokens with the message SHM-'.strval($order_id), 'Please go on https://chaturbate.com/sexhackme and tip '.intval($total/0.05).' tokens with the message SHM-'.strval($order_id),
true ); true );
*/ */
// Empty cart // Empty cart
WC()->cart->empty_cart(); WC()->cart->empty_cart();
return array( return array(
'result' => 'success', 'result' => 'success',
'redirect' => $this->get_return_url( $order ), 'redirect' => $this->get_return_url( $order ),
); );
} }
/* /*
// XXX We don't use anything special here. // XXX We don't use anything special here.
// Display payment fields during checkout // Display payment fields during checkout
public function payment_fields() { public function payment_fields() {
......
...@@ -135,6 +135,11 @@ function save_sexhack_video_forms( $post_id) ...@@ -135,6 +135,11 @@ function save_sexhack_video_forms( $post_id)
if(array_key_exists('video_private', $_POST) && in_array($_POST['video_private'], array('Y','N'))) if(array_key_exists('video_private', $_POST) && in_array($_POST['video_private'], array('Y','N')))
$video->private = $_POST['video_private']; $video->private = $_POST['video_private'];
// Premium Video is PPV?
if(array_key_exists('premium_is_ppv', $_POST) && in_array($_POST['premium_is_ppv'], array('Y','N')))
$video->premium_is_ppv = $_POST['premium_is_ppv'];
// Video visible // Video visible
if(array_key_exists('video_visible', $_POST) && in_array($_POST['video_visible'], array('Y','N'))) if(array_key_exists('video_visible', $_POST) && in_array($_POST['video_visible'], array('Y','N')))
$video->visible = $_POST['video_visible']; $video->visible = $_POST['video_visible'];
...@@ -148,6 +153,7 @@ function save_sexhack_video_forms( $post_id) ...@@ -148,6 +153,7 @@ function save_sexhack_video_forms( $post_id)
if(array_key_exists('video_type', $_POST) && in_array($_POST['video_type'], array('VR', 'FLAT'))) if(array_key_exists('video_type', $_POST) && in_array($_POST['video_type'], array('VR', 'FLAT')))
$video->video_type = $_POST['video_type']; $video->video_type = $_POST['video_type'];
// VR Projection // VR Projection
if(array_key_exists('video_vr_projection', $_POST) && in_array($_POST['video_vr_projection'], array('VR180_LR','VR360_LR'))) if(array_key_exists('video_vr_projection', $_POST) && in_array($_POST['video_vr_projection'], array('VR180_LR','VR360_LR')))
$video->vr_projection = $_POST['video_vr_projection']; $video->vr_projection = $_POST['video_vr_projection'];
......
...@@ -47,7 +47,7 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -47,7 +47,7 @@ if(!class_exists('SexHackMe_Plugin')) {
public function __construct() public function __construct()
{ {
define( 'SH_VERSION', '0.0.2' ); define( 'SH_VERSION', '0.0.3' );
define( 'SH_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) ); define( 'SH_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'SH_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); define( 'SH_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'SH_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'SH_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
...@@ -190,6 +190,7 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -190,6 +190,7 @@ if(!class_exists('SexHackMe_Plugin')) {
download_public varchar(1024) DEFAULT NULL, download_public varchar(1024) DEFAULT NULL,
download_members varchar(1024) DEFAULT NULL, download_members varchar(1024) DEFAULT NULL,
download_premium varchar(1024) DEFAULT NULL, download_premium varchar(1024) DEFAULT NULL,
premium_is_ppv ENUM('Y', 'N') NOT NULL DEFAULT 'N',
size_public varchar(256) DEFAULT NULL, size_public varchar(256) DEFAULT NULL,
size_members varchar(256) DEFAULT NULL, size_members varchar(256) DEFAULT NULL,
size_premium varchar(256) DEFAULT NULL, size_premium varchar(256) DEFAULT NULL,
...@@ -218,6 +219,7 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -218,6 +219,7 @@ if(!class_exists('SexHackMe_Plugin')) {
KEY post_id (post_id), KEY post_id (post_id),
KEY slug (slug), KEY slug (slug),
KEY price (price), KEY price (price),
KEY premium_is_ppv (premium_is_ppc),
KEY video_type (video_type), KEY video_type (video_type),
KEY product_id (product_id) KEY product_id (product_id)
) {$charset_collate}; ) {$charset_collate};
......
...@@ -108,6 +108,12 @@ if($video->product_id > 0) ...@@ -108,6 +108,12 @@ if($video->product_id > 0)
<label>USD:</label> <label>USD:</label>
<input type='text' name="video_price" value='<?php echo esc_attr( $video->price ); ?>' /> <input type='text' name="video_price" value='<?php echo esc_attr( $video->price ); ?>' />
</p> </p>
<p>
<h4>is premium a PPV?</h4>
<input type='radio' name='premium_is_ppv' value='Y' <?php if($video->premium_is_ppv=='Y') echo "checked"; ?>>Yes</input>
<input type='radio' name='premium_is_ppv' value='N' <?php if($video->premium_is_ppv=='N') echo "checked"; ?>>No</input>
</p>
<p> <p>
<?php <?php
$vaccess=array('public','members','premium'); $vaccess=array('public','members','premium');
......
...@@ -62,6 +62,18 @@ $plans = wp_SexHackMe\sh_get_subscription_plans(); ...@@ -62,6 +62,18 @@ $plans = wp_SexHackMe\sh_get_subscription_plans();
} }
?> ?>
</table> </table>
<table class="form-table">
<tr align="top">
<td>
<label><b>Premium member discount on PPVs</b></label><br>
<input type='number' name='sexhack_wcpms_premium_discount' value="<?php echo get_option('sexhack_wcpms_premium_discount', '0'); ?>" />
<p class="description">insert a percentage of discount all premium members will have on PPV videos</p>
</td>
</tr>
</table>
<?php do_settings_sections( 'sexhackme-wcpms-settings-email' ); ?> <?php do_settings_sections( 'sexhackme-wcpms-settings-email' ); ?>
<table class="form-table"> <table class="form-table">
<tr align="top"> <tr align="top">
......
...@@ -120,6 +120,13 @@ foreach(array('public','members','premium') as $level) { ?> ...@@ -120,6 +120,13 @@ foreach(array('public','members','premium') as $level) { ?>
<input type='radio' name='video_isdownload_<?php echo $level; ?>' value='N' <?php if(!$video->has_downloads($level)) echo "checked"; ?>>No</input> <input type='radio' name='video_isdownload_<?php echo $level; ?>' value='N' <?php if(!$video->has_downloads($level)) echo "checked"; ?>>No</input>
</p> </p>
<?php if($level == 'premium') { ?> <?php if($level == 'premium') { ?>
<p>
<label>Is premium video a PPV?</label>
<input type='radio' name='premium_is_ppv' value='Y' <?php if($video->premium_is_ppv=='Y') echo "checked"; ?>>Yes</input>
<input type='radio' name='premium_is_ppv' value='N' <?php if($video->premium_is_ppv=='N') echo "checked"; ?>>No</input>
</p>
<p> <p>
<label> Create Members video HLS from this video? </label> <label> Create Members video HLS from this video? </label>
<input type='radio' name='video_createMembers_<?php echo $level; ?>' value='Y' >Yes</input> <input type='radio' name='video_createMembers_<?php echo $level; ?>' value='Y' >Yes</input>
......
...@@ -84,6 +84,7 @@ get_header(); ?> ...@@ -84,6 +84,7 @@ get_header(); ?>
$video_preview = $video->preview; $video_preview = $video->preview;
$gif_preview = $video->gif_small; $gif_preview = $video->gif_small;
$gif = $video->gif; $gif = $video->gif;
$premium_is_ppv = $video->premium_is_ppv;
$categories = $video->get_categories(true); $categories = $video->get_categories(true);
...@@ -116,7 +117,7 @@ get_header(); ?> ...@@ -116,7 +117,7 @@ get_header(); ?>
else else
{ {
if(user_has_premium_access() || $video->user_bought_video()) { if(user_has_premium_access() || $video->user_bought_video()) {
if($hls_premium) $tab = 'subscribers'; if($hls_premium && ((!$premium_is_ppv) || $video->user_bought_video() )) $tab = 'subscribers';
elseif($hls_members) $tab = 'members'; elseif($hls_members) $tab = 'members';
else $tab = 'public'; else $tab = 'public';
} }
...@@ -162,7 +163,7 @@ get_header(); ?> ...@@ -162,7 +163,7 @@ get_header(); ?>
break; break;
case "subscribers": case "subscribers":
if(user_has_premium_access() || $video->user_bought_video()) if((user_has_premium_access() && !$premium_is_ppv) || $video->user_bought_video())
{ {
if($filterurl && $hls_premium && $video->video_type=="VR") if($filterurl && $hls_premium && $video->video_type=="VR")
echo do_shortcode( "[sexvideo url=\"".wp_nonce_url($filterurl.$sh_video."/premium/".basename($hls_premium), 'shm_premium_video-'.$video->id)."\" posters=\"".$thumb."\"]" ); echo do_shortcode( "[sexvideo url=\"".wp_nonce_url($filterurl.$sh_video."/premium/".basename($hls_premium), 'shm_premium_video-'.$video->id)."\" posters=\"".$thumb."\"]" );
...@@ -252,6 +253,9 @@ get_header(); ?> ...@@ -252,6 +253,9 @@ get_header(); ?>
</div> </div>
<?php } ?> <?php } ?>
<?php if(!$video->user_bought_video() && $hls_premium && $premium_is_ppv) { ?>
<h3><a href="<?php echo get_permalink($video->product_id); ?>">Buy unlimited full access to this video</a></h3>
<?php } ?>
<?php if($video->has_downloads()) { ?> <?php if($video->has_downloads()) { ?>
<h3><a href="<?php echo get_permalink($video->product_id); ?>">Download the full lenght hi-res version of this video</a></h3> <h3><a href="<?php echo get_permalink($video->product_id); ?>">Download the full lenght hi-res version of this video</a></h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment