Plugin Directory

Changeset 1972647


Ignore:
Timestamp:
11/11/2018 10:36:01 PM (7 years ago)
Author:
pwallner
Message:

Corrected bug with variable products

Location:
disable-downloadable-repeat-purchase
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • disable-downloadable-repeat-purchase/tags/1.2.3/disable-downloadable-repeat-purchase.php

    r1800801 r1972647  
    44 * Plugin URI:              https://wordpress.org/plugins/disable-downloadable-repeat-purchase/
    55 * Description:             Disable the ability for logged in users to purchase items they already own that are downloadable. Links are provided on the product page for ease of re-download. It does not apply to products the customer has been refunded for. It checks if the product has been purchased and is available to download on their account.
    6  * Version:                 1.2.2
     6 * Version:                 1.2.3
    77 * Author:                  MCPat.com
    88 * Author URI:              https://www.mcpat.com
     
    1313 * License:                 GPLv2
    1414 * License URI:             https://www.gnu.org/licenses/gpl-2.0.html
    15  * WC requires at least:    3.0.0
    16  * WC tested up to:         3.2.6
     15 * WC requires at least:    3.4.0
     16 * WC tested up to:         3.5.1
    1717 */
    1818
     
    205205    // Get the ID for the current product
    206206    $product_id = $product->get_ID();
    207      
    208     // check if wpml is active
     207   
     208    //old
     209    /*// check if wpml is active
    209210    $multi = false;
    210211    if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     
    227228            }
    228229        }
    229     } else {
     230    } else {*/
    230231        // return false if the customer has bought the product and is currently available for download
    231232        if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id )  && $product->get_downloadable() && get_post_meta( $product_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    232233            $purchasable = false;
    233234        }
    234     }
     235    //}
    235236    return $purchasable;
    236237}
     
    250251    if ( $product->is_type( 'variable' ) ) { //variabel product
    251252        foreach ( $product->get_children() as $variation_id ) {
     253            /*//Old
    252254            if ($multi) {
    253255                $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() );
     
    255257                $translations = $sitepress->get_element_translations($trid, 'product');
    256258                foreach( $translations as $lang=>$translation){
     259                   
    257260                    // Render the purchase restricted message if it has been purchased
    258261                    if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && get_post_meta( $translation->element_id, '_downloadable', true ) == 'yes' && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    259262                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
     263                        echo "<script> console.log('PHP-first: ',",$variation_id,");</script>";
    260264                        //break;//?
    261265                    }
    262266                }
    263             } else {
    264                 foreach ( $product->get_children() as $variation_id ) {
    265                     // Render the purchase restricted message if it has been purchased
     267            } else {*/
    266268                    if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $variation_id ) && get_post_meta( $variation_id, '_downloadable', true ) == 'yes' && get_post_meta( $variation_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    267269                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
     270                        echo "<script> console.log('PHP-first-s: ',",$variation_id,");</script>";
    268271                    }
    269                 }
    270             }
     272            //}
    271273        }
    272274    } else { //normal product   
     
    289291            //jQuery(window).load(function () {
    290292            jQuery(document).ready ( function(){
    291                     if (jQuery(window).width() >= 470){
    292                         jQuery(".woocommerce-info").attr('style', 'min-width: 470px; animation-name: slide-in');
     293                    if (jQuery(window).width() >= 500){
     294                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px;min-width: 500px');
    293295                    } else {
    294                         jQuery(".woocommerce-info").attr('style', 'animation-name: slide-in');
     296                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px');
    295297                    }
    296                     jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in');
     298                    jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in;animation-delay: 0s;animation-duration: 0s');
    297299                });
    298300            </script><?php
     
    351353add_action( 'woocommerce_single_product_summary', 'mcpat_ddrp_repeat_purchase_disabled_message', 31 );
    352354
     355function mcpat_ddrp_render_variation_non_purchasable_message2( $product, $no_repeats_id ) {
     356   
     357    // Double-check we're looking at a variable product
     358    if ( $product->is_type( 'variable' ) && $product->has_child() ) {
     359       
     360        $variation_purchasable = true;
     361       
     362        foreach ( $product->get_available_variations() as $variation ) {
     363           
     364            // only show this message for non-purchasable variations matching our ID
     365            if ( $no_repeats_id == $variation['variation_id'] ) {
     366                $variation_purchasable = false;
     367                //echo "<script> console.log('PHP: ',",sanitize_html_class( $variation['variation_id'] ),");</script>";
     368                echo '<div class="woocommerce"><div class="woocommerce-info wc-nonpurchasable-message js-variation-' . sanitize_html_class( $variation['variation_id'] ) . '">You\'ve already purchased this product! It can only be purchased once.</div></div>';
     369            }
     370        }
     371    }
     372       
     373    if ( ! $variation_purchasable ) {
     374        wc_enqueue_js("
     375            jQuery('.variations_form')
     376                .on( 'woocommerce_variation_select_change', function( event ) {
     377                    jQuery('.wc-nonpurchasable-message').hide();
     378                })
     379                .on( 'found_variation', function( event, variation ) {
     380                    jQuery('.wc-nonpurchasable-message').hide();
     381                    if ( ! variation.is_purchasable ) {
     382                        jQuery( '.wc-nonpurchasable-message.js-variation-' + variation.variation_id ).show();
     383                    }
     384                })
     385            .find( '.variations select' ).change();
     386        ");
     387    }
     388}
    353389function mcpat_ddrp_render_variation_non_purchasable_message( $product, $no_repeats_id) {
    354390    // Double-check we're looking at a variable product
     
    379415                //jQuery(window).load(function () {
    380416                jQuery(document).ready ( function(){
    381                     if (jQuery(window).width() >= 470){
    382                         jQuery(".woocommerce-info").attr('style', 'min-width: 470px; animation-name: slide-in');
     417                    if (jQuery(window).width() >= 500){
     418                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px;min-width: 500px');
    383419                    } else {
    384                         jQuery(".woocommerce-info").attr('style', 'animation-name: slide-in');
     420                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px');
    385421                    }
    386                     jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in');
     422                    jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in;animation-delay: 0s;animation-duration: 0s');
    387423                });
    388424                </script><?php
     
    477513function mcpat_ddrp_is_requirements_met() {
    478514    $min_wp  = '4.7';
    479     $min_wc = '3.0';
     515    $min_wc = '3.4';
    480516       
    481517    // Check for WordPress version
  • disable-downloadable-repeat-purchase/tags/1.2.3/readme.txt

    r1800801 r1972647  
    55Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=p%2er%2ewallner%40gmail%2ecom&lc=AT&item_name=mcpat&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
    66Requires at Least: 4.7
    7 Tested Up To: 4.9
     7Tested Up To: 5.0
    88Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language
    9 Stable tag: 1.2.2
    10 WC requires at least: 3.0.0
    11 WC tested up to: 3.2.6
     9Stable tag: 1.2.3
     10WC requires at least: 3.4.0
     11WC tested up to: 3.5.1
    1212License: GPLv2 or later
    1313License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5959== Changelog ==
    6060
     61= 1.2.3 =
     62- Bug fix on variable products
     63
    6164= 1.2.2 =
    6265- Fix showing expire date
  • disable-downloadable-repeat-purchase/trunk/disable-downloadable-repeat-purchase.php

    r1800801 r1972647  
    44 * Plugin URI:              https://wordpress.org/plugins/disable-downloadable-repeat-purchase/
    55 * Description:             Disable the ability for logged in users to purchase items they already own that are downloadable. Links are provided on the product page for ease of re-download. It does not apply to products the customer has been refunded for. It checks if the product has been purchased and is available to download on their account.
    6  * Version:                 1.2.2
     6 * Version:                 1.2.3
    77 * Author:                  MCPat.com
    88 * Author URI:              https://www.mcpat.com
     
    1313 * License:                 GPLv2
    1414 * License URI:             https://www.gnu.org/licenses/gpl-2.0.html
    15  * WC requires at least:    3.0.0
    16  * WC tested up to:         3.2.6
     15 * WC requires at least:    3.4.0
     16 * WC tested up to:         3.5.1
    1717 */
    1818
     
    205205    // Get the ID for the current product
    206206    $product_id = $product->get_ID();
    207      
    208     // check if wpml is active
     207   
     208    //old
     209    /*// check if wpml is active
    209210    $multi = false;
    210211    if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     
    227228            }
    228229        }
    229     } else {
     230    } else {*/
    230231        // return false if the customer has bought the product and is currently available for download
    231232        if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id )  && $product->get_downloadable() && get_post_meta( $product_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    232233            $purchasable = false;
    233234        }
    234     }
     235    //}
    235236    return $purchasable;
    236237}
     
    250251    if ( $product->is_type( 'variable' ) ) { //variabel product
    251252        foreach ( $product->get_children() as $variation_id ) {
     253            /*//Old
    252254            if ($multi) {
    253255                $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() );
     
    255257                $translations = $sitepress->get_element_translations($trid, 'product');
    256258                foreach( $translations as $lang=>$translation){
     259                   
    257260                    // Render the purchase restricted message if it has been purchased
    258261                    if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && get_post_meta( $translation->element_id, '_downloadable', true ) == 'yes' && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    259262                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
     263                        echo "<script> console.log('PHP-first: ',",$variation_id,");</script>";
    260264                        //break;//?
    261265                    }
    262266                }
    263             } else {
    264                 foreach ( $product->get_children() as $variation_id ) {
    265                     // Render the purchase restricted message if it has been purchased
     267            } else {*/
    266268                    if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $variation_id ) && get_post_meta( $variation_id, '_downloadable', true ) == 'yes' && get_post_meta( $variation_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    267269                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
     270                        echo "<script> console.log('PHP-first-s: ',",$variation_id,");</script>";
    268271                    }
    269                 }
    270             }
     272            //}
    271273        }
    272274    } else { //normal product   
     
    289291            //jQuery(window).load(function () {
    290292            jQuery(document).ready ( function(){
    291                     if (jQuery(window).width() >= 470){
    292                         jQuery(".woocommerce-info").attr('style', 'min-width: 470px; animation-name: slide-in');
     293                    if (jQuery(window).width() >= 500){
     294                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px;min-width: 500px');
    293295                    } else {
    294                         jQuery(".woocommerce-info").attr('style', 'animation-name: slide-in');
     296                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px');
    295297                    }
    296                     jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in');
     298                    jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in;animation-delay: 0s;animation-duration: 0s');
    297299                });
    298300            </script><?php
     
    351353add_action( 'woocommerce_single_product_summary', 'mcpat_ddrp_repeat_purchase_disabled_message', 31 );
    352354
     355function mcpat_ddrp_render_variation_non_purchasable_message2( $product, $no_repeats_id ) {
     356   
     357    // Double-check we're looking at a variable product
     358    if ( $product->is_type( 'variable' ) && $product->has_child() ) {
     359       
     360        $variation_purchasable = true;
     361       
     362        foreach ( $product->get_available_variations() as $variation ) {
     363           
     364            // only show this message for non-purchasable variations matching our ID
     365            if ( $no_repeats_id == $variation['variation_id'] ) {
     366                $variation_purchasable = false;
     367                //echo "<script> console.log('PHP: ',",sanitize_html_class( $variation['variation_id'] ),");</script>";
     368                echo '<div class="woocommerce"><div class="woocommerce-info wc-nonpurchasable-message js-variation-' . sanitize_html_class( $variation['variation_id'] ) . '">You\'ve already purchased this product! It can only be purchased once.</div></div>';
     369            }
     370        }
     371    }
     372       
     373    if ( ! $variation_purchasable ) {
     374        wc_enqueue_js("
     375            jQuery('.variations_form')
     376                .on( 'woocommerce_variation_select_change', function( event ) {
     377                    jQuery('.wc-nonpurchasable-message').hide();
     378                })
     379                .on( 'found_variation', function( event, variation ) {
     380                    jQuery('.wc-nonpurchasable-message').hide();
     381                    if ( ! variation.is_purchasable ) {
     382                        jQuery( '.wc-nonpurchasable-message.js-variation-' + variation.variation_id ).show();
     383                    }
     384                })
     385            .find( '.variations select' ).change();
     386        ");
     387    }
     388}
    353389function mcpat_ddrp_render_variation_non_purchasable_message( $product, $no_repeats_id) {
    354390    // Double-check we're looking at a variable product
     
    379415                //jQuery(window).load(function () {
    380416                jQuery(document).ready ( function(){
    381                     if (jQuery(window).width() >= 470){
    382                         jQuery(".woocommerce-info").attr('style', 'min-width: 470px; animation-name: slide-in');
     417                    if (jQuery(window).width() >= 500){
     418                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px;min-width: 500px');
    383419                    } else {
    384                         jQuery(".woocommerce-info").attr('style', 'animation-name: slide-in');
     420                        jQuery(".page-notifications").attr('style', 'animation-name: slide-in;animation-delay: 0s;animation-duration: 0s;Top:100px');
    385421                    }
    386                     jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in');
     422                    jQuery(".notice_text").attr('style', 'animation-name: opacity_text_in;animation-delay: 0s;animation-duration: 0s');
    387423                });
    388424                </script><?php
     
    477513function mcpat_ddrp_is_requirements_met() {
    478514    $min_wp  = '4.7';
    479     $min_wc = '3.0';
     515    $min_wc = '3.4';
    480516       
    481517    // Check for WordPress version
  • disable-downloadable-repeat-purchase/trunk/readme.txt

    r1800801 r1972647  
    55Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=p%2er%2ewallner%40gmail%2ecom&lc=AT&item_name=mcpat&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
    66Requires at Least: 4.7
    7 Tested Up To: 4.9
     7Tested Up To: 5.0
    88Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language
    9 Stable tag: 1.2.2
    10 WC requires at least: 3.0.0
    11 WC tested up to: 3.2.6
     9Stable tag: 1.2.3
     10WC requires at least: 3.4.0
     11WC tested up to: 3.5.1
    1212License: GPLv2 or later
    1313License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5959== Changelog ==
    6060
     61= 1.2.3 =
     62- Bug fix on variable products
     63
    6164= 1.2.2 =
    6265- Fix showing expire date
Note: See TracChangeset for help on using the changeset viewer.