Changeset 1751902
- Timestamp:
- 10/24/2017 01:56:43 PM (8 years ago)
- Location:
- disable-downloadable-repeat-purchase
- Files:
-
- 10 added
- 2 edited
- 3 copied
-
assets/screenshot-6.png (added)
-
assets/screenshot-7.png (added)
-
tags/1.2.0 (copied) (copied from disable-downloadable-repeat-purchase/trunk)
-
tags/1.2.0/css (added)
-
tags/1.2.0/css/switchery.min.css (added)
-
tags/1.2.0/disable-downloadable-repeat-purchase.php (copied) (copied from disable-downloadable-repeat-purchase/trunk/disable-downloadable-repeat-purchase.php) (7 diffs)
-
tags/1.2.0/js (added)
-
tags/1.2.0/js/switchery.min.js (added)
-
tags/1.2.0/readme.txt (copied) (copied from disable-downloadable-repeat-purchase/trunk/readme.txt) (2 diffs)
-
trunk/css (added)
-
trunk/css/switchery.min.css (added)
-
trunk/disable-downloadable-repeat-purchase.php (modified) (7 diffs)
-
trunk/js (added)
-
trunk/js/switchery.min.js (added)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disable-downloadable-repeat-purchase/tags/1.2.0/disable-downloadable-repeat-purchase.php
r1733382 r1751902 4 4 * Plugin URI: https://wordpress.org/plugins/disable-downloadable-repeat-purchase/ 5 5 * 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.16 * Version: 1.2.0 7 7 * Author: MCPat.com 8 8 * Author URI: https://www.mcpat.com … … 24 24 add_action('init', 'mcpat_ddrp_language_load'); 25 25 26 //select on each product 27 add_action( 'woocommerce_product_after_variable_attributes', 'mcpat_ddrp_variation_settings_fields', 10, 3 ); 28 add_action( 'woocommerce_save_product_variation', 'mcpat_ddrp_save_variation_settings_fields', 10, 2 ); 29 add_action( 'woocommerce_product_options_general_product_data', 'mcpat_ddrp_custom_general_fields' ); 30 add_action( 'woocommerce_process_product_meta', 'mcpat_ddrp_custom_general_fields_save' ); 31 if ( 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 } 37 function mcpat_ddrp_js_lock_fields_ids( $ids ){ 38 // Add locked field IDs 39 $ids[] = '_mcpat_ddrp_deactivated'; 40 return $ids; 41 } 42 function 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 } 127 function 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 26 185 function mcpat_ddrp_disable_repeat_purchase( $purchasable, $product ) { 27 186 // Don't run on parents of variations, … … 49 208 foreach( $translations as $lang=>$translation){ 50 209 // 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' ) { 52 211 $purchasable = false; 53 212 break; … … 56 215 } else { 57 216 // 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' ) { 59 218 $purchasable = false; 60 219 } … … 78 237 foreach ( $product->get_children() as $variation_id ) { 79 238 if ($multi) { 239 $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() ); 80 240 $trid = $sitepress->get_element_trid($variation_id, 'post_product'); 81 241 $translations = $sitepress->get_element_translations($trid, 'product'); 82 242 foreach( $translations as $lang=>$translation){ 83 243 // 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' ) { 85 245 mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id); 86 246 //break;//? … … 90 250 foreach ( $product->get_children() as $variation_id ) { 91 251 // 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' ) { 93 253 mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id); 94 254 } … … 102 262 $translations = $sitepress->get_element_translations($orig_ppost, 'product'); 103 263 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' ) 105 265 $gekauft=true; 106 266 $trid[]= $translation->element_id; 107 267 } 108 268 } 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' ) 110 270 $gekauft = true; 111 271 } -
disable-downloadable-repeat-purchase/tags/1.2.0/readme.txt
r1733382 r1751902 7 7 Tested Up To: 4.8 8 8 Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language 9 Stable tag: 1. 1.19 Stable tag: 1.2.0 10 10 WC requires at least: 3.0.0 11 11 WC tested up to: 3.2.0 … … 48 48 == Screenshots == 49 49 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) 50 1. Nonpurchasable-message in theme Twenty Seventeen 51 2. Nonpurchasable-message in theme Storefront 52 3. Nonpurchasable-message in theme Shopkeeper 53 4. Nonpurchasable-message in theme Shop Isle 54 5. Nonpurchasable-message at variable product 55 6. Setting simple product 56 7. Setting variable product 52 57 53 58 54 59 == Changelog == 60 61 = 1.2.0 = 62 - Enable/Disable option on each simple/variable product 55 63 56 64 = 1.1.1 = -
disable-downloadable-repeat-purchase/trunk/disable-downloadable-repeat-purchase.php
r1733382 r1751902 4 4 * Plugin URI: https://wordpress.org/plugins/disable-downloadable-repeat-purchase/ 5 5 * 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.16 * Version: 1.2.0 7 7 * Author: MCPat.com 8 8 * Author URI: https://www.mcpat.com … … 24 24 add_action('init', 'mcpat_ddrp_language_load'); 25 25 26 //select on each product 27 add_action( 'woocommerce_product_after_variable_attributes', 'mcpat_ddrp_variation_settings_fields', 10, 3 ); 28 add_action( 'woocommerce_save_product_variation', 'mcpat_ddrp_save_variation_settings_fields', 10, 2 ); 29 add_action( 'woocommerce_product_options_general_product_data', 'mcpat_ddrp_custom_general_fields' ); 30 add_action( 'woocommerce_process_product_meta', 'mcpat_ddrp_custom_general_fields_save' ); 31 if ( 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 } 37 function mcpat_ddrp_js_lock_fields_ids( $ids ){ 38 // Add locked field IDs 39 $ids[] = '_mcpat_ddrp_deactivated'; 40 return $ids; 41 } 42 function 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 } 127 function 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 26 185 function mcpat_ddrp_disable_repeat_purchase( $purchasable, $product ) { 27 186 // Don't run on parents of variations, … … 49 208 foreach( $translations as $lang=>$translation){ 50 209 // 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' ) { 52 211 $purchasable = false; 53 212 break; … … 56 215 } else { 57 216 // 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' ) { 59 218 $purchasable = false; 60 219 } … … 78 237 foreach ( $product->get_children() as $variation_id ) { 79 238 if ($multi) { 239 $orig_ppost = apply_filters( 'wpml_object_id',$variation_id, get_post_type( $variation_id ), true, $sitepress->get_default_language() ); 80 240 $trid = $sitepress->get_element_trid($variation_id, 'post_product'); 81 241 $translations = $sitepress->get_element_translations($trid, 'product'); 82 242 foreach( $translations as $lang=>$translation){ 83 243 // 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' ) { 85 245 mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id); 86 246 //break;//? … … 90 250 foreach ( $product->get_children() as $variation_id ) { 91 251 // 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' ) { 93 253 mcpat_ddrp_render_variation_non_purchasable_message( $product, $variation_id); 94 254 } … … 102 262 $translations = $sitepress->get_element_translations($orig_ppost, 'product'); 103 263 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' ) 105 265 $gekauft=true; 106 266 $trid[]= $translation->element_id; 107 267 } 108 268 } 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' ) 110 270 $gekauft = true; 111 271 } -
disable-downloadable-repeat-purchase/trunk/readme.txt
r1733382 r1751902 7 7 Tested Up To: 4.8 8 8 Tags: woocommerce, downloads, downloadable, repeat purchase, wordpress, wordpress.org,wpml,multilanguage,language 9 Stable tag: 1. 1.19 Stable tag: 1.2.0 10 10 WC requires at least: 3.0.0 11 11 WC tested up to: 3.2.0 … … 48 48 == Screenshots == 49 49 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) 50 1. Nonpurchasable-message in theme Twenty Seventeen 51 2. Nonpurchasable-message in theme Storefront 52 3. Nonpurchasable-message in theme Shopkeeper 53 4. Nonpurchasable-message in theme Shop Isle 54 5. Nonpurchasable-message at variable product 55 6. Setting simple product 56 7. Setting variable product 52 57 53 58 54 59 == Changelog == 60 61 = 1.2.0 = 62 - Enable/Disable option on each simple/variable product 55 63 56 64 = 1.1.1 =
Note: See TracChangeset
for help on using the changeset viewer.