Plugin Directory

Changeset 1751902


Ignore:
Timestamp:
10/24/2017 01:56:43 PM (8 years ago)
Author:
pwallner
Message:

Options added

Location:
disable-downloadable-repeat-purchase
Files:
10 added
2 edited
3 copied

Legend:

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

    r1733382 r1751902  
    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.1.1
     6 * Version:                 1.2.0
    77 * Author:                  MCPat.com
    88 * Author URI:              https://www.mcpat.com
     
    2424add_action('init', 'mcpat_ddrp_language_load');
    2525
     26//select on each product
     27add_action( 'woocommerce_product_after_variable_attributes', 'mcpat_ddrp_variation_settings_fields', 10, 3 );
     28add_action( 'woocommerce_save_product_variation', 'mcpat_ddrp_save_variation_settings_fields', 10, 2 );
     29add_action( 'woocommerce_product_options_general_product_data', 'mcpat_ddrp_custom_general_fields' );
     30add_action( 'woocommerce_process_product_meta', 'mcpat_ddrp_custom_general_fields_save' );
     31if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     32        global $sitepress;
     33        if ( isset( $sitepress )) { // avoids a fatal error with Polylang
     34            add_filter( 'wcml_js_lock_fields_ids', 'mcpat_ddrp_js_lock_fields_ids' );
     35        }   
     36}
     37function mcpat_ddrp_js_lock_fields_ids( $ids ){
     38        // Add locked field IDs
     39        $ids[] = '_mcpat_ddrp_deactivated';
     40        return $ids;
     41}
     42function mcpat_ddrp_variation_settings_fields( $loop, $variation_data, $variation ){
     43        // Checkbox
     44        $lock = false;
     45        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     46                global $sitepress;
     47                if ( isset( $sitepress )) {
     48                    $orig_ppost = apply_filters( 'wpml_object_id', $variation->ID, get_post_type( $variation->ID ), true, $sitepress->get_default_language() );
     49                    if ( $orig_ppost != $variation->ID ) {
     50                        $lock = true;
     51                    }
     52                }
     53        }
     54
     55        echo '<div class="show_if_variation_downloadable"><table style="height: 1px !important; padding: 0px; margin-top: 5px; display: inline-block;"></table>';//<div class="variable_custom_field show_if_software">';// style="display: inline-block;">';
     56        echo '<h1 class="wp-heading-inline">' . __( 'Disable Downloadable Repeat Purchase Options', 'disable-downloadable-repeat-purchase' ) . '</h1>';
     57
     58        if ( $lock ) {         
     59                //quick and dirty because wcml hook is not working in variables
     60                ?>
     61                <div class="variable_custom_field">
     62                <p class="form-field _mcpat_ddrp_deactivated_field ">
     63                <label for="_mcpat_ddrp_deactivated"><?php _e( 'Disable repeat purchase', 'disable-downloadable-repeat-purchase'); ?></label><!--<span class="woocommerce-help-tip"></span>-->
     64                <input type="checkbox" class="checkbox js-switch-x<?php echo $variation->ID; ?>" name="_mcpat_ddrp_is_enabled[<?php echo $variation->ID; ?>]" id="_mcpat_ddrp_is_enabled" value="yes" <?php
     65                    if ( get_post_meta( $orig_ppost, '_mcpat_ddrp_is_enabled', true ) != 'no') {
     66                        echo 'checked';
     67                    }
     68                ?> disabled="disabled">
     69                <script type="text/javascript">
     70                        // Default
     71                        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-x<?php echo $variation->ID; ?>'));
     72                        elems.forEach(function(html) {
     73                            var switchery = new Switchery(html, { color: '#7c8bc7', size: 'small' });
     74                        });
     75                </script>
     76                <?php       
     77                echo '<img src="' . WCML_PLUGIN_URL . '/res/images/locked.png" alt="' .
     78                    __( 'This field is locked for editing because WPML will copy its value from the original language.', 'disable-downloadable-repeat-purchase' ) .
     79                    '" title="' . __( 'This field is locked for editing because WPML will copy its value from the original language.', 'disable-downloadable-repeat-purchase' ) .
     80                    '" style="position: relative; left: 2px; top: 5px; display: inline;">';
     81                ?>
     82                </p></div><?php
     83               
     84               
     85        } else {
     86            $ddrp_is_enabled_switchery = 'no';
     87            if ( get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true ) != 'no') {
     88                $ddrp_is_enabled_switchery = 'yes';
     89            }
     90            //echo '<script>console.log("Wos: ' . get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true ) . '")</script>';
     91            woocommerce_wp_checkbox(
     92                array(
     93                    'id'            => '_mcpat_ddrp_is_enabled',
     94                    'name'          => '_mcpat_ddrp_is_enabled[' . $variation->ID . ']',
     95                    'wrapper_class' => 'mcpat_ddrp_enabled',
     96                    'class'         => 'js-switch-x' . $variation->ID,
     97                    'label'         => __( 'Disable repeat purchase', 'disable-downloadable-repeat-purchase' ),
     98                    'description'   => __( 'Enable this option if this product can only be purchased once', 'disable-downloadable-repeat-purchase' ),
     99                    'desc_tip'      => true,
     100                    'value'         => $ddrp_is_enabled_switchery
     101                    )
     102            );
     103            //get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true )
     104            ?>
     105            <script type="text/javascript">
     106                        // Default
     107                        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-x<?php echo $variation->ID; ?>'));
     108                        elems.forEach(function(html) {
     109                            var switchery = new Switchery(html, { color: '#7c8bc7', size: 'small' });
     110                        });
     111            </script><?php
     112        }
     113        echo '</div>';
     114    }
     115    function mcpat_ddrp_save_variation_settings_fields( $post_id ) {
     116        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     117                global $sitepress;
     118                if ( isset( $sitepress )) {
     119                    if ($post_id != apply_filters( 'wpml_object_id', $post_id, get_post_type( $post_id ), true, $sitepress->get_default_language() ))
     120                        return;
     121                }
     122        }
     123        // Checkbox
     124        $checkbox = isset( $_POST['_mcpat_ddrp_is_enabled'][ $post_id ] ) ? 'yes' : 'no';
     125        update_post_meta( $post_id, '_mcpat_ddrp_is_enabled', $checkbox );
     126    }
     127function mcpat_ddrp_custom_general_fields() {
     128        echo '<script src="' . plugins_url("/js/switchery.min.js", __FILE__) . '"></script>';
     129        echo '<link rel="stylesheet" href="' . plugins_url("/css/switchery.min.css", __FILE__) .'" />';
     130
     131        global $woocommerce, $post;
     132        $product = wc_get_product( $post->ID);
     133        $orig_ppost = $post->ID;
     134        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     135                global $sitepress;
     136                if ( isset( $sitepress )) {
     137                    $orig_ppost = apply_filters( 'wpml_object_id', $post->ID, get_post_type( $post->ID ), true, $sitepress->get_default_language() );
     138                }
     139        }
     140
     141            echo '<div class="show_if_downloadable">'; 
     142            echo '<div class="options_group show_if_simple"><h1 class="wp-heading-inline" style="margin-left: 10px;">' . __( 'Disable Downloadable Repeat Purchase Options', 'disable-downloadable-repeat-purchase' ) . '</h1>';
     143            // Custom fields will be created here...
     144            woocommerce_wp_checkbox(
     145                    array(
     146                        'id'            => '_mcpat_ddrp_deactivated',
     147                        'name'          => '_mcpat_ddrp_is_enabled_s',
     148                        'class'         => 'js-switch-y',
     149                        'label'         => __('Disable repeat purchase', 'disable-downloadable-repeat-purchase' ),
     150                        'desc_tip'      => true,
     151                        'description'   => __( 'Enable this option if this product can only be purchased once', 'disable-downloadable-repeat-purchase' ),
     152                        'value'         => get_post_meta( $orig_ppost, '_mcpat_ddrp_is_enabled', true )
     153
     154                    )
     155                );
     156            echo '</div></div>';
     157            ?>
     158            <script type="text/javascript">
     159                        var elem = document.querySelector('.js-switch-y');
     160                        var switcheri = new Switchery(elem, { color: '#7c8bc7', size: 'small' });           
     161                        <?php if ($post->ID != $orig_ppost) { ?>
     162                            switcheri.disable();
     163                        <?php } ?>
     164            </script><?php
     165    }
     166    function mcpat_ddrp_custom_general_fields_save( $post_id ){
     167        // Checkbox
     168        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     169                global $sitepress;
     170                if ( isset( $sitepress )) {
     171                    if ($post_id != apply_filters( 'wpml_object_id', $post_id, get_post_type( $post_id ), true, $sitepress->get_default_language() ))
     172                        return;
     173                }
     174        }
     175        //global $product;
     176        $_product = wc_get_product( $post_id );
     177        if ( $_product->is_type( 'variable' ) ) {
     178            return;
     179        }
     180        $woocommerce_checkbox = isset( $_POST['_mcpat_ddrp_is_enabled_s'] ) ? 'yes' : 'no';
     181        update_post_meta( $post_id, '_mcpat_ddrp_is_enabled', $woocommerce_checkbox );
     182    }
     183
     184
    26185function mcpat_ddrp_disable_repeat_purchase( $purchasable, $product ) {
    27186    // Don't run on parents of variations,
     
    49208        foreach( $translations as $lang=>$translation){
    50209            // return false if the customer has bought the product and is currently available for download
    51             if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() ) {
     210            if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    52211                $purchasable = false;
    53212                break;
     
    56215    } else {
    57216        // return false if the customer has bought the product and is currently available for download
    58         if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id )  && $product->get_downloadable() ) {
     217        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' ) {
    59218            $purchasable = false;
    60219        }
     
    78237        foreach ( $product->get_children() as $variation_id ) {
    79238            if ($multi) {
     239                $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() );
    80240                $trid = $sitepress->get_element_trid($variation_id, 'post_product');
    81241                $translations = $sitepress->get_element_translations($trid, 'product');
    82242                foreach( $translations as $lang=>$translation){
    83243                    // Render the purchase restricted message if it has been purchased
    84                     if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) ) {
     244                    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' ) {
    85245                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
    86246                        //break;//?
     
    90250                foreach ( $product->get_children() as $variation_id ) {
    91251                    // Render the purchase restricted message if it has been purchased
    92                     if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $variation_id ) ) {
     252                    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' ) {
    93253                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
    94254                    }
     
    102262            $translations = $sitepress->get_element_translations($orig_ppost, 'product');
    103263            foreach( $translations as $lang=>$translation){
    104                 if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() )
     264                if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' )
    105265                    $gekauft=true;
    106266                $trid[]= $translation->element_id;
    107267            }
    108268        } else {
    109             if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product->get_ID() ) && $product->get_downloadable() )
     269            if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product->get_ID() ) && $product->get_downloadable() && get_post_meta( $product->get_ID(), '_mcpat_ddrp_is_enabled', true ) != 'no' )
    110270                $gekauft = true;
    111271        }
  • disable-downloadable-repeat-purchase/tags/1.2.0/readme.txt

    r1733382 r1751902  
    77Tested Up To: 4.8
    88Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language
    9 Stable tag: 1.1.1
     9Stable tag: 1.2.0
    1010WC requires at least: 3.0.0
    1111WC tested up to: 3.2.0
     
    4848== Screenshots ==
    4949
    50 1. The disabled message with default WooCommerce styles (without available download)
    51 2. The disabled message with default WooCommerce styles (with available download in German)
     501. Nonpurchasable-message in theme Twenty Seventeen
     512. Nonpurchasable-message in theme Storefront
     523. Nonpurchasable-message in theme Shopkeeper
     534. Nonpurchasable-message in theme Shop Isle
     545. Nonpurchasable-message at variable product
     556. Setting simple product
     567. Setting variable product
    5257
    5358
    5459== Changelog ==
     60
     61= 1.2.0 =
     62- Enable/Disable option on each simple/variable product
    5563
    5664= 1.1.1 =
  • disable-downloadable-repeat-purchase/trunk/disable-downloadable-repeat-purchase.php

    r1733382 r1751902  
    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.1.1
     6 * Version:                 1.2.0
    77 * Author:                  MCPat.com
    88 * Author URI:              https://www.mcpat.com
     
    2424add_action('init', 'mcpat_ddrp_language_load');
    2525
     26//select on each product
     27add_action( 'woocommerce_product_after_variable_attributes', 'mcpat_ddrp_variation_settings_fields', 10, 3 );
     28add_action( 'woocommerce_save_product_variation', 'mcpat_ddrp_save_variation_settings_fields', 10, 2 );
     29add_action( 'woocommerce_product_options_general_product_data', 'mcpat_ddrp_custom_general_fields' );
     30add_action( 'woocommerce_process_product_meta', 'mcpat_ddrp_custom_general_fields_save' );
     31if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     32        global $sitepress;
     33        if ( isset( $sitepress )) { // avoids a fatal error with Polylang
     34            add_filter( 'wcml_js_lock_fields_ids', 'mcpat_ddrp_js_lock_fields_ids' );
     35        }   
     36}
     37function mcpat_ddrp_js_lock_fields_ids( $ids ){
     38        // Add locked field IDs
     39        $ids[] = '_mcpat_ddrp_deactivated';
     40        return $ids;
     41}
     42function mcpat_ddrp_variation_settings_fields( $loop, $variation_data, $variation ){
     43        // Checkbox
     44        $lock = false;
     45        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     46                global $sitepress;
     47                if ( isset( $sitepress )) {
     48                    $orig_ppost = apply_filters( 'wpml_object_id', $variation->ID, get_post_type( $variation->ID ), true, $sitepress->get_default_language() );
     49                    if ( $orig_ppost != $variation->ID ) {
     50                        $lock = true;
     51                    }
     52                }
     53        }
     54
     55        echo '<div class="show_if_variation_downloadable"><table style="height: 1px !important; padding: 0px; margin-top: 5px; display: inline-block;"></table>';//<div class="variable_custom_field show_if_software">';// style="display: inline-block;">';
     56        echo '<h1 class="wp-heading-inline">' . __( 'Disable Downloadable Repeat Purchase Options', 'disable-downloadable-repeat-purchase' ) . '</h1>';
     57
     58        if ( $lock ) {         
     59                //quick and dirty because wcml hook is not working in variables
     60                ?>
     61                <div class="variable_custom_field">
     62                <p class="form-field _mcpat_ddrp_deactivated_field ">
     63                <label for="_mcpat_ddrp_deactivated"><?php _e( 'Disable repeat purchase', 'disable-downloadable-repeat-purchase'); ?></label><!--<span class="woocommerce-help-tip"></span>-->
     64                <input type="checkbox" class="checkbox js-switch-x<?php echo $variation->ID; ?>" name="_mcpat_ddrp_is_enabled[<?php echo $variation->ID; ?>]" id="_mcpat_ddrp_is_enabled" value="yes" <?php
     65                    if ( get_post_meta( $orig_ppost, '_mcpat_ddrp_is_enabled', true ) != 'no') {
     66                        echo 'checked';
     67                    }
     68                ?> disabled="disabled">
     69                <script type="text/javascript">
     70                        // Default
     71                        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-x<?php echo $variation->ID; ?>'));
     72                        elems.forEach(function(html) {
     73                            var switchery = new Switchery(html, { color: '#7c8bc7', size: 'small' });
     74                        });
     75                </script>
     76                <?php       
     77                echo '<img src="' . WCML_PLUGIN_URL . '/res/images/locked.png" alt="' .
     78                    __( 'This field is locked for editing because WPML will copy its value from the original language.', 'disable-downloadable-repeat-purchase' ) .
     79                    '" title="' . __( 'This field is locked for editing because WPML will copy its value from the original language.', 'disable-downloadable-repeat-purchase' ) .
     80                    '" style="position: relative; left: 2px; top: 5px; display: inline;">';
     81                ?>
     82                </p></div><?php
     83               
     84               
     85        } else {
     86            $ddrp_is_enabled_switchery = 'no';
     87            if ( get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true ) != 'no') {
     88                $ddrp_is_enabled_switchery = 'yes';
     89            }
     90            //echo '<script>console.log("Wos: ' . get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true ) . '")</script>';
     91            woocommerce_wp_checkbox(
     92                array(
     93                    'id'            => '_mcpat_ddrp_is_enabled',
     94                    'name'          => '_mcpat_ddrp_is_enabled[' . $variation->ID . ']',
     95                    'wrapper_class' => 'mcpat_ddrp_enabled',
     96                    'class'         => 'js-switch-x' . $variation->ID,
     97                    'label'         => __( 'Disable repeat purchase', 'disable-downloadable-repeat-purchase' ),
     98                    'description'   => __( 'Enable this option if this product can only be purchased once', 'disable-downloadable-repeat-purchase' ),
     99                    'desc_tip'      => true,
     100                    'value'         => $ddrp_is_enabled_switchery
     101                    )
     102            );
     103            //get_post_meta( $variation->ID, '_mcpat_ddrp_is_enabled', true )
     104            ?>
     105            <script type="text/javascript">
     106                        // Default
     107                        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-x<?php echo $variation->ID; ?>'));
     108                        elems.forEach(function(html) {
     109                            var switchery = new Switchery(html, { color: '#7c8bc7', size: 'small' });
     110                        });
     111            </script><?php
     112        }
     113        echo '</div>';
     114    }
     115    function mcpat_ddrp_save_variation_settings_fields( $post_id ) {
     116        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     117                global $sitepress;
     118                if ( isset( $sitepress )) {
     119                    if ($post_id != apply_filters( 'wpml_object_id', $post_id, get_post_type( $post_id ), true, $sitepress->get_default_language() ))
     120                        return;
     121                }
     122        }
     123        // Checkbox
     124        $checkbox = isset( $_POST['_mcpat_ddrp_is_enabled'][ $post_id ] ) ? 'yes' : 'no';
     125        update_post_meta( $post_id, '_mcpat_ddrp_is_enabled', $checkbox );
     126    }
     127function mcpat_ddrp_custom_general_fields() {
     128        echo '<script src="' . plugins_url("/js/switchery.min.js", __FILE__) . '"></script>';
     129        echo '<link rel="stylesheet" href="' . plugins_url("/css/switchery.min.css", __FILE__) .'" />';
     130
     131        global $woocommerce, $post;
     132        $product = wc_get_product( $post->ID);
     133        $orig_ppost = $post->ID;
     134        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     135                global $sitepress;
     136                if ( isset( $sitepress )) {
     137                    $orig_ppost = apply_filters( 'wpml_object_id', $post->ID, get_post_type( $post->ID ), true, $sitepress->get_default_language() );
     138                }
     139        }
     140
     141            echo '<div class="show_if_downloadable">'; 
     142            echo '<div class="options_group show_if_simple"><h1 class="wp-heading-inline" style="margin-left: 10px;">' . __( 'Disable Downloadable Repeat Purchase Options', 'disable-downloadable-repeat-purchase' ) . '</h1>';
     143            // Custom fields will be created here...
     144            woocommerce_wp_checkbox(
     145                    array(
     146                        'id'            => '_mcpat_ddrp_deactivated',
     147                        'name'          => '_mcpat_ddrp_is_enabled_s',
     148                        'class'         => 'js-switch-y',
     149                        'label'         => __('Disable repeat purchase', 'disable-downloadable-repeat-purchase' ),
     150                        'desc_tip'      => true,
     151                        'description'   => __( 'Enable this option if this product can only be purchased once', 'disable-downloadable-repeat-purchase' ),
     152                        'value'         => get_post_meta( $orig_ppost, '_mcpat_ddrp_is_enabled', true )
     153
     154                    )
     155                );
     156            echo '</div></div>';
     157            ?>
     158            <script type="text/javascript">
     159                        var elem = document.querySelector('.js-switch-y');
     160                        var switcheri = new Switchery(elem, { color: '#7c8bc7', size: 'small' });           
     161                        <?php if ($post->ID != $orig_ppost) { ?>
     162                            switcheri.disable();
     163                        <?php } ?>
     164            </script><?php
     165    }
     166    function mcpat_ddrp_custom_general_fields_save( $post_id ){
     167        // Checkbox
     168        if ( array_key_exists('wpml_object_id', $GLOBALS['wp_filter']) ) {
     169                global $sitepress;
     170                if ( isset( $sitepress )) {
     171                    if ($post_id != apply_filters( 'wpml_object_id', $post_id, get_post_type( $post_id ), true, $sitepress->get_default_language() ))
     172                        return;
     173                }
     174        }
     175        //global $product;
     176        $_product = wc_get_product( $post_id );
     177        if ( $_product->is_type( 'variable' ) ) {
     178            return;
     179        }
     180        $woocommerce_checkbox = isset( $_POST['_mcpat_ddrp_is_enabled_s'] ) ? 'yes' : 'no';
     181        update_post_meta( $post_id, '_mcpat_ddrp_is_enabled', $woocommerce_checkbox );
     182    }
     183
     184
    26185function mcpat_ddrp_disable_repeat_purchase( $purchasable, $product ) {
    27186    // Don't run on parents of variations,
     
    49208        foreach( $translations as $lang=>$translation){
    50209            // return false if the customer has bought the product and is currently available for download
    51             if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() ) {
     210            if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' ) {
    52211                $purchasable = false;
    53212                break;
     
    56215    } else {
    57216        // return false if the customer has bought the product and is currently available for download
    58         if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id )  && $product->get_downloadable() ) {
     217        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' ) {
    59218            $purchasable = false;
    60219        }
     
    78237        foreach ( $product->get_children() as $variation_id ) {
    79238            if ($multi) {
     239                $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() );
    80240                $trid = $sitepress->get_element_trid($variation_id, 'post_product');
    81241                $translations = $sitepress->get_element_translations($trid, 'product');
    82242                foreach( $translations as $lang=>$translation){
    83243                    // Render the purchase restricted message if it has been purchased
    84                     if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) ) {
     244                    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' ) {
    85245                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
    86246                        //break;//?
     
    90250                foreach ( $product->get_children() as $variation_id ) {
    91251                    // Render the purchase restricted message if it has been purchased
    92                     if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $variation_id ) ) {
     252                    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' ) {
    93253                        mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id);
    94254                    }
     
    102262            $translations = $sitepress->get_element_translations($orig_ppost, 'product');
    103263            foreach( $translations as $lang=>$translation){
    104                 if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() )
     264                if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $translation->element_id ) && $product->get_downloadable() && get_post_meta( $translation->element_id, '_mcpat_ddrp_is_enabled', true ) != 'no' )
    105265                    $gekauft=true;
    106266                $trid[]= $translation->element_id;
    107267            }
    108268        } else {
    109             if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product->get_ID() ) && $product->get_downloadable() )
     269            if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product->get_ID() ) && $product->get_downloadable() && get_post_meta( $product->get_ID(), '_mcpat_ddrp_is_enabled', true ) != 'no' )
    110270                $gekauft = true;
    111271        }
  • disable-downloadable-repeat-purchase/trunk/readme.txt

    r1733382 r1751902  
    77Tested Up To: 4.8
    88Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language
    9 Stable tag: 1.1.1
     9Stable tag: 1.2.0
    1010WC requires at least: 3.0.0
    1111WC tested up to: 3.2.0
     
    4848== Screenshots ==
    4949
    50 1. The disabled message with default WooCommerce styles (without available download)
    51 2. The disabled message with default WooCommerce styles (with available download in German)
     501. Nonpurchasable-message in theme Twenty Seventeen
     512. Nonpurchasable-message in theme Storefront
     523. Nonpurchasable-message in theme Shopkeeper
     534. Nonpurchasable-message in theme Shop Isle
     545. Nonpurchasable-message at variable product
     556. Setting simple product
     567. Setting variable product
    5257
    5358
    5459== Changelog ==
     60
     61= 1.2.0 =
     62- Enable/Disable option on each simple/variable product
    5563
    5664= 1.1.1 =
Note: See TracChangeset for help on using the changeset viewer.