Changeset 3805284
- Timestamp:
- 11/16/2026 01:46:30 PM (19 hours ago)
- Location:
- cut-and-pack-for-woocommerce
- Files:
-
- 18 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from cut-and-pack-for-woocommerce/trunk )
-
tags/1.1.0/assets/js/admin.js (modified) (2 diffs)
-
tags/1.1.0/assets/js/calculator.js (modified) (7 diffs)
-
tags/1.1.0/cut-and-pack-for-woocommerce.php (modified) (2 diffs)
-
tags/1.1.0/includes/class-cutpack-admin.php (modified) (5 diffs)
-
tags/1.1.0/includes/class-cutpack-cart.php (modified) (9 diffs)
-
tags/1.1.0/includes/class-cutpack-frontend.php (modified) (4 diffs)
-
tags/1.1.0/includes/class-cutpack-settings.php (modified) (4 diffs)
-
tags/1.1.0/languages/cut-and-pack-for-woocommerce.pot (modified) (12 diffs)
-
tags/1.1.0/readme.txt (modified) (5 diffs)
-
trunk/assets/js/admin.js (modified) (2 diffs)
-
trunk/assets/js/calculator.js (modified) (7 diffs)
-
trunk/cut-and-pack-for-woocommerce.php (modified) (2 diffs)
-
trunk/includes/class-cutpack-admin.php (modified) (5 diffs)
-
trunk/includes/class-cutpack-cart.php (modified) (9 diffs)
-
trunk/includes/class-cutpack-frontend.php (modified) (4 diffs)
-
trunk/includes/class-cutpack-settings.php (modified) (4 diffs)
-
trunk/languages/cut-and-pack-for-woocommerce.pot (modified) (12 diffs)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cut-and-pack-for-woocommerce/tags/1.1.0/assets/js/admin.js
r3800171 r3805284 13 13 14 14 $( panel + ' .cutpack-show-if-packs' ).toggle( 'packs' === mode ); 15 $( '.cutpack-variation-field' ).toggle( 'packs' === mode && 'area' === measure ); 15 16 $( panel + ' .cutpack-show-if-cut' ).toggle( 'cut' === mode ); 16 17 $( panel + ' .cutpack-show-if-area' ).toggle( 'area' === measure ); … … 27 28 $( function () { 28 29 $( document ).on( 'change', '#_cutpack_mode, #_cutpack_measure', refresh ); 30 $( document ).on( 'woocommerce_variations_loaded woocommerce_variations_added', refresh ); 29 31 refresh(); 30 32 } ); -
cut-and-pack-for-woocommerce/tags/1.1.0/assets/js/calculator.js
r3800171 r3805284 19 19 return; 20 20 } 21 var form = box.closest( 'form .cart' );21 var form = box.closest( 'form' ); 22 22 if ( ! form ) { 23 23 return; … … 25 25 26 26 var qty = form.querySelector( 'input[name="quantity"]' ); 27 var button = form.querySelector( ' .single_add_to_cart_button' );27 var button = form.querySelector( '[type="submit"], .single_add_to_cart_button' ); 28 28 var inputs = box.querySelectorAll( '.cutpack-input' ); 29 29 var resultEl = box.querySelector( '.cutpack-result' ); … … 68 68 } 69 69 70 function calculate() { 70 /** 71 * What applies right now: the product itself, or the chosen variation. 72 * The variation id is read from the form every time, never cached. 73 */ 74 function current() { 75 if ( ! d.variable ) { 76 return { ok: true, coverage: d.coverage, unitPrice: d.unitPrice, maxQty: -1 }; 77 } 78 var field = form.querySelector( 'input[name="variation_id"]' ); 79 var id = field ? parseInt( field.value, 10 ) || 0 : 0; 80 if ( ! id ) { 81 return { ok: false, id: 0, message: d.i18n.chooseOption }; 82 } 83 var v = d.variations[ id ]; 84 if ( ! v || ! v.purchasable ) { 85 return { ok: false, id: id, message: d.i18n.unavailable }; 86 } 87 return { ok: true, id: id, coverage: v.coverage, unitPrice: v.unitPrice, maxQty: v.maxQty }; 88 } 89 90 function calculate( cur ) { 71 91 var entered; 72 92 … … 93 113 94 114 if ( 'packs' === d.mode ) { 95 var packs = Math.max( 1, Math.ceil( entered / d.coverage - EPSILON ) );96 var charged = round( packs * d.coverage, 6 );115 var packs = Math.max( 1, Math.ceil( entered / cur.coverage - EPSILON ) ); 116 var charged = round( packs * cur.coverage, 6 ); 97 117 // Price of one box is rounded to whole pennies first, as on the server. 98 var boxPrice = round( d.coverage * d.unitPrice, d.currency.decimals ); 118 var boxPrice = round( cur.coverage * cur.unitPrice, d.currency.decimals ); 119 if ( cur.maxQty >= 0 && packs > cur.maxQty ) { 120 var inStock = format( 1 === cur.maxQty ? d.i18n.oneBox : d.i18n.manyBoxes, cur.maxQty ); 121 return { error: format( d.i18n.stock, inStock, formatAmount( cur.maxQty * cur.coverage ), d.unit ) }; 122 } 99 123 return { packs: packs, charged: charged, price: packs * boxPrice }; 100 124 } 101 125 102 126 var amount = d.step > 0 ? round( Math.ceil( entered / d.step - EPSILON ) * d.step, 6 ) : entered; 103 return { packs: 1, charged: amount, price: round( amount * d.unitPrice, d.currency.decimals ) };127 return { packs: 1, charged: amount, price: round( amount * cur.unitPrice, d.currency.decimals ) }; 104 128 } 105 129 … … 121 145 } 122 146 147 /** Write only when the text changes, so screen readers don't repeat themselves. */ 148 function setText( el, text ) { 149 if ( el.textContent !== text ) { 150 el.textContent = text; 151 } 152 } 153 154 /** The quantity box is hidden, so the browser must never block the form over it. */ 155 function relaxQuantity() { 156 if ( qty ) { 157 qty.removeAttribute( 'min' ); 158 qty.removeAttribute( 'max' ); 159 qty.removeAttribute( 'step' ); 160 } 161 } 162 163 /** The calculator replaces the normal quantity box. WooCommerce may show it again, so hide it on every update. */ 164 function hideQuantity() { 165 var wrap = qty && button ? qty.closest( '.quantity' ) : null; 166 if ( wrap ) { 167 wrap.style.setProperty( 'display', 'none', 'important' ); 168 } 169 } 170 123 171 function update() { 172 hideQuantity(); 173 var cur = current(); 174 if ( ! cur.ok ) { 175 setText( resultEl, cur.message ); 176 setText( errorEl, '' ); 177 setButton( false ); 178 return; 179 } 180 124 181 if ( isEmpty() ) { 125 resultEl.textContent = '';126 errorEl.textContent = '';127 setButton( false ); 128 return; 129 } 130 131 var r = calculate( );182 setText( resultEl, '' ); 183 setText( errorEl, '' ); 184 setButton( false ); 185 return; 186 } 187 188 var r = calculate( cur ); 132 189 133 190 if ( r.error ) { 134 resultEl.textContent = '';135 errorEl.textContent = r.error;136 setButton( false ); 137 return; 138 } 139 140 errorEl.textContent = '';191 setText( resultEl, '' ); 192 setText( errorEl, r.error ); 193 setButton( false ); 194 return; 195 } 196 197 setText( errorEl, '' ); 141 198 142 199 if ( 'packs' === d.mode ) { 143 200 var boxes = format( 1 === r.packs ? d.i18n.oneBox : d.i18n.manyBoxes, r.packs ); 144 resultEl.textContent = format( d.i18n.resultPacks, boxes, formatAmount( r.charged ), d.unit, formatPrice( r.price) );201 setText( resultEl, format( d.i18n.resultPacks, boxes, formatAmount( r.charged ), d.unit, formatPrice( r.price ) ) ); 145 202 if ( qty ) { 146 203 qty.value = r.packs; 147 204 } 148 205 } else { 149 resultEl.textContent = format( d.i18n.resultCut, formatAmount( r.charged ), d.unit, formatPrice( r.price) );206 setText( resultEl, format( d.i18n.resultCut, formatAmount( r.charged ), d.unit, formatPrice( r.price ) ) ); 150 207 if ( qty ) { 151 208 qty.value = 1; … … 153 210 } 154 211 212 relaxQuantity(); 155 213 setButton( true ); 156 214 } 157 215 158 // The calculator replaces the normal quantity box. 159 if ( qty ) { 160 var wrap = qty.closest( '.quantity' ); 161 if ( wrap ) { 162 wrap.style.display = 'none'; 163 } 216 /** Re-run after WooCommerce (or the block) has finished its own changes. */ 217 function later() { 218 window.setTimeout( function () { 219 update(); 220 if ( window.requestAnimationFrame ) { 221 window.requestAnimationFrame( update ); 222 } 223 }, 0 ); 164 224 } 165 225 … … 168 228 } 169 229 230 if ( d.variable ) { 231 // Any interaction with the form may change the chosen variation. 232 [ 'click', 'change', 'input', 'keyup' ].forEach( function ( name ) { 233 form.addEventListener( name, later ); 234 } ); 235 236 // WooCommerce's own events, when jQuery is on the page. 237 if ( window.jQuery ) { 238 window.jQuery( form ).on( 'found_variation show_variation hide_variation reset_data check_variations', later ); 239 } 240 241 // Backstop for themes that change the chosen option without any event. 242 var lastId = null; 243 window.setInterval( function () { 244 var now = current(); 245 var key = String( now.id || 0 ) + ( now.ok ? '1' : '0' ); 246 if ( key !== lastId ) { 247 lastId = key; 248 update(); 249 } 250 }, 250 ); 251 } 252 253 // Drop the hidden quantity's limits just before the browser checks the form. 254 if ( button ) { 255 button.addEventListener( 'click', relaxQuantity, true ); 256 } 257 170 258 // Stop the form being sent with an invalid size (e.g. by pressing Enter). 171 259 form.addEventListener( 'submit', function ( event ) { 172 var r = isEmpty() ? { error: d.i18n.invalid } : calculate(); 260 var cur = current(); 261 var r = ! cur.ok ? { error: cur.message } : ( isEmpty() ? { error: d.i18n.invalid } : calculate( cur ) ); 262 relaxQuantity(); 173 263 if ( r.error ) { 174 264 event.preventDefault(); 175 errorEl.textContent = r.error;265 setText( errorEl, r.error ); 176 266 setButton( false ); 177 267 } -
cut-and-pack-for-woocommerce/tags/1.1.0/cut-and-pack-for-woocommerce.php
r3800171 r3805284 3 3 * Plugin Name: Cut & Pack for WooCommerce 4 4 * Description: Made-to-measure pricing for WooCommerce. Sell by m² or metre, round up to whole packs, and show the price live. 5 * Version: 1. 0.05 * Version: 1.1.0 6 6 * Requires at least: 6.9 7 7 * Requires PHP: 7.4 … … 21 21 defined( 'ABSPATH' ) || exit; 22 22 23 define( 'CUTPACK_VERSION', '1. 0.0' );23 define( 'CUTPACK_VERSION', '1.1.0' ); 24 24 define( 'CUTPACK_FILE', __FILE__ ); 25 25 define( 'CUTPACK_PATH', plugin_dir_path( __FILE__ ) ); -
cut-and-pack-for-woocommerce/tags/1.1.0/includes/class-cutpack-admin.php
r3800171 r3805284 20 20 add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'render_panel' ) ); 21 21 add_action( 'woocommerce_admin_process_product_object', array( __CLASS__, 'save' ) ); 22 add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'render_variation_field' ), 10, 3 ); 23 add_action( 'woocommerce_admin_process_variation_object', array( __CLASS__, 'save_variation' ), 10, 2 ); 22 24 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ) ); 23 25 add_filter( 'woocommerce_get_settings_products', array( __CLASS__, 'store_settings' ), 10, 2 ); … … 78 80 'label' => __( 'Made to measure', 'cut-and-pack-for-woocommerce' ), 79 81 'target' => 'cutpack_product_data', 80 'class' => array( 'show_if_simple', ' hide_if_variable', 'hide_if_grouped', 'hide_if_external' ),82 'class' => array( 'show_if_simple', 'show_if_variable', 'hide_if_grouped', 'hide_if_external' ), 81 83 'priority' => 65, 82 84 ); … … 147 149 148 150 echo '<p class="form-field cutpack-price-note"><span class="description">'; 149 echo esc_html__( 'The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 151 if ( $product_object instanceof WC_Product && $product_object->is_type( 'variable' ) ) { 152 echo esc_html__( 'The price comes from each variation\'s own Regular price, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 153 } else { 154 echo esc_html__( 'The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 155 } 150 156 echo '</span></p>'; 151 157 … … 227 233 228 234 /** 235 * Optional per-variation pack size, shown in each variation's panel. 236 * 237 * @param int $loop Position in the loop. 238 * @param array $variation_data Variation data. 239 * @param WP_Post $variation Variation post. 240 */ 241 public static function render_variation_field( $loop, $variation_data, $variation ) { 242 $value = get_post_meta( $variation->ID, Cutpack_Settings::meta_key( 'coverage' ), true ); 243 ?> 244 <div class="cutpack-variation-field form-row form-row-full"> 245 <label for="cutpack_variation_coverage_<?php echo esc_attr( $loop ); ?>"> 246 <?php echo esc_html( sprintf( /* translators: %s: unit */ __( 'Pack size: coverage per pack (%s)', 'cut-and-pack-for-woocommerce' ), Cutpack_Settings::unit_label( Cutpack_Settings::MEASURE_AREA ) ) ); ?> 247 </label> 248 <input type="text" inputmode="decimal" class="short" id="cutpack_variation_coverage_<?php echo esc_attr( $loop ); ?>" name="cutpack_variation_coverage[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr__( 'Same as the product', 'cut-and-pack-for-woocommerce' ); ?>" /> 249 <span class="description"><?php esc_html_e( 'Only for packs. Leave empty to use the number from the "Made to measure" tab.', 'cut-and-pack-for-woocommerce' ); ?></span> 250 </div> 251 <?php 252 } 253 254 /** 255 * Save the per-variation pack size. WooCommerce has already checked the nonce. 256 * 257 * @param WC_Product_Variation $variation Variation being saved. 258 * @param int $i Position in the posted list. 259 */ 260 public static function save_variation( $variation, $i ) { 261 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce checked by WooCommerce before this hook runs. 262 if ( ! isset( $_POST['cutpack_variation_coverage'][ $i ] ) || is_array( $_POST['cutpack_variation_coverage'][ $i ] ) ) { 263 return; 264 } 265 $raw = sanitize_text_field( wp_unslash( $_POST['cutpack_variation_coverage'][ $i ] ) ); 266 // phpcs:enable 267 268 if ( ! current_user_can( 'edit_post', $variation->get_parent_id() ) ) { 269 return; 270 } 271 $variation->update_meta_data( Cutpack_Settings::meta_key( 'coverage' ), Cutpack_Settings::to_positive_decimal( $raw ) ); 272 } 273 274 /** 229 275 * Save the tab's fields. WooCommerce has already checked the nonce and permissions. 230 276 * … … 278 324 } 279 325 280 if ( '' === $product->get_regular_price() ) { 326 // A variable product keeps its prices on the variations. 327 if ( ! $product->is_type( 'variable' ) && '' === $product->get_regular_price() ) { 281 328 $problems[] = __( 'Enter a Regular price on the General tab (price per m² or per metre).', 'cut-and-pack-for-woocommerce' ); 282 329 } -
cut-and-pack-for-woocommerce/tags/1.1.0/includes/class-cutpack-cart.php
r3800171 r3805284 35 35 36 36 /** 37 * Variation chosen for each product during this add-to-cart request, as 38 * seen by the validation filter (which WooCommerce gives the variation, 39 * even when the form only posted attributes). 40 * 41 * @var int[] 42 */ 43 private static $chosen = array(); 44 45 /** 37 46 * Register hooks. 38 47 */ 39 48 public static function init() { 40 add_filter( 'woocommerce_add_to_cart_validation', array( __CLASS__, 'validate' ), 10, 2 ); 41 add_filter( 'woocommerce_add_to_cart_quantity', array( __CLASS__, 'quantity' ), 10, 2 ); 42 add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_item_data' ), 10, 2 ); 43 49 add_filter( 'woocommerce_add_to_cart_validation', array( __CLASS__, 'validate' ), 10, 4 ); 50 add_filter( 'woocommerce_add_to_cart_quantity', array( __CLASS__, 'quantity' ), 10, 3 ); 51 add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_item_data' ), 10, 3 ); 52 53 add_filter( 'woocommerce_add_cart_item', array( __CLASS__, 'lock_quantity' ), 15 ); 44 54 add_filter( 'woocommerce_add_cart_item', array( __CLASS__, 'apply_price' ), 20 ); 45 55 add_filter( 'woocommerce_get_cart_item_from_session', array( __CLASS__, 'apply_price' ), 20 ); … … 75 85 76 86 /** 87 * Work out the parent product and variation being added. 88 * 89 * WooCommerce passes the variation ID to some filters but not all, and 90 * `?add-to-cart=<variation id>` passes the variation as the product. 91 * Every server path resolves it here so they cannot disagree. 92 * 93 * @param int $product_id Product ID as received by the filter. 94 * @param int $variation_id Variation ID as received by the filter, or 0. 95 * @return int[] array( product ID, variation ID ). 96 */ 97 private static function resolve_ids( $product_id, $variation_id = 0 ) { 98 $product_id = absint( $product_id ); 99 $variation_id = absint( $variation_id ); 100 101 $product = wc_get_product( $product_id ); 102 if ( $product instanceof WC_Product && $product->is_type( 'variation' ) ) { 103 return array( (int) $product->get_parent_id(), $product_id ); 104 } 105 106 if ( ! $variation_id && isset( self::$chosen[ $product_id ] ) ) { 107 return array( $product_id, self::$chosen[ $product_id ] ); 108 } 109 110 if ( ! $variation_id && isset( $_REQUEST['variation_id'] ) && is_scalar( $_REQUEST['variation_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- WooCommerce add-to-cart forms carry no nonce; the ID is only used after checking it belongs to the product. 111 $variation_id = absint( wp_unslash( $_REQUEST['variation_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended 112 } 113 114 return array( $product_id, $variation_id ); 115 } 116 117 /** 77 118 * Calculate the posted input for a product. 78 119 * 79 * @param int $product_id Product ID. 120 * @param int $product_id Product ID. 121 * @param int $variation_id Variation ID, or 0. 80 122 * @return array|WP_Error|null Null if the product doesn't use the calculator. 81 123 */ 82 private static function posted_result( $product_id ) { 124 private static function posted_result( $product_id, $variation_id = 0 ) { 125 list( $product_id, $variation_id ) = self::resolve_ids( $product_id, $variation_id ); 126 83 127 $product = wc_get_product( $product_id ); 84 128 if ( ! Cutpack_Settings::is_enabled( $product ) ) { 85 129 return null; 86 130 } 87 return Cutpack_Calculator::calculate( Cutpack_Settings::get( $product ), self::posted_input() ); 131 132 if ( $product->is_type( 'variable' ) ) { 133 $variation = Cutpack_Settings::owned_variation( $product, $variation_id ); 134 if ( ! $variation ) { 135 return new WP_Error( 'cutpack_variation', __( 'Choose an option first.', 'cut-and-pack-for-woocommerce' ) ); 136 } 137 } 138 139 return Cutpack_Calculator::calculate( Cutpack_Settings::get_for( $product_id, $variation_id ), self::posted_input() ); 88 140 } 89 141 … … 91 143 * Block adding a measured product without a valid size. 92 144 * 93 * @param bool $passed Whether earlier checks passed. 94 * @param int $product_id Product ID. 145 * @param bool $passed Whether earlier checks passed. 146 * @param int $product_id Product ID. 147 * @param int $quantity Quantity (unused). 148 * @param int $variation_id Variation ID. 95 149 * @return bool 96 150 */ 97 public static function validate( $passed, $product_id ) { 98 $result = self::posted_result( $product_id ); 151 public static function validate( $passed, $product_id, $quantity = 1, $variation_id = 0 ) { 152 if ( absint( $variation_id ) ) { 153 self::$chosen[ absint( $product_id ) ] = absint( $variation_id ); 154 } 155 $result = self::posted_result( $product_id, $variation_id ); 99 156 if ( null === $result || ! $passed ) { 100 157 return $passed; … … 111 168 * whatever quantity the browser sent. 112 169 * 113 * @param int $quantity Quantity sent. 114 * @param int $product_id Product ID. 170 * @param int $quantity Quantity sent. 171 * @param int $product_id Product ID. 172 * @param int $variation_id Variation ID. 115 173 * @return int 116 174 */ 117 public static function quantity( $quantity, $product_id ) {118 $result = self::posted_result( $product_id );175 public static function quantity( $quantity, $product_id, $variation_id = 0 ) { 176 $result = self::posted_result( $product_id, $variation_id ); 119 177 if ( null === $result || is_wp_error( $result ) ) { 120 178 return $quantity; … … 126 184 * Store the measurements on the cart item. 127 185 * 128 * @param array $data Cart item data. 129 * @param int $product_id Product ID. 186 * @param array $data Cart item data. 187 * @param int $product_id Product ID. 188 * @param int $variation_id Variation ID. 130 189 * @return array 131 190 */ 132 public static function add_item_data( $data, $product_id ) {133 $result = self::posted_result( $product_id );191 public static function add_item_data( $data, $product_id, $variation_id = 0 ) { 192 $result = self::posted_result( $product_id, $variation_id ); 134 193 if ( null === $result || is_wp_error( $result ) ) { 135 194 return $data; … … 154 213 155 214 /** 215 * The stored measurement is authoritative: make the line quantity match it, 216 * so quantity and measurements can never disagree. 217 * 218 * @param array $item Cart item. 219 * @return array 220 */ 221 public static function lock_quantity( $item ) { 222 if ( empty( $item[ self::KEY ] ) || ! isset( $item[ self::KEY ]['packs'] ) ) { 223 return $item; 224 } 225 $settings = Cutpack_Settings::get_for( $item['product_id'], isset( $item['variation_id'] ) ? $item['variation_id'] : 0 ); 226 $item['quantity'] = Cutpack_Settings::MODE_PACKS === $settings['mode'] ? (int) $item[ self::KEY ]['packs'] : 1; 227 return $item; 228 } 229 230 /** 156 231 * Set the price of one cart unit (one pack, or one cut piece). 157 232 * … … 163 238 return $item; 164 239 } 165 $settings = Cutpack_Settings::get( $item['product_id'] ); 166 $price = Cutpack_Calculator::line_unit_price( $settings, $item[ self::KEY ], self::base_price( $item['product_id'] ) ); 240 $variation_id = isset( $item['variation_id'] ) ? (int) $item['variation_id'] : 0; 241 $settings = Cutpack_Settings::get_for( $item['product_id'], $variation_id ); 242 $price = Cutpack_Calculator::line_unit_price( $settings, $item[ self::KEY ], self::base_price( $variation_id ? $variation_id : $item['product_id'] ) ); 167 243 168 244 /** … … 285 361 return $item_data; 286 362 } 287 $settings = Cutpack_Settings::get ( $item['product_id']);363 $settings = Cutpack_Settings::get_for( $item['product_id'], isset( $item['variation_id'] ) ? $item['variation_id'] : 0 ); 288 364 foreach ( self::describe( $item[ self::KEY ], $settings, $item['quantity'] ) as $line ) { 289 365 $item_data[] = array( … … 307 383 return; 308 384 } 309 $settings = Cutpack_Settings::get ( $values['product_id']);385 $settings = Cutpack_Settings::get_for( $values['product_id'], isset( $values['variation_id'] ) ? $values['variation_id'] : 0 ); 310 386 foreach ( self::describe( $values[ self::KEY ], $settings, $values['quantity'] ) as $line ) { 311 387 $order_item->add_meta_data( $line[0], $line[1], true ); -
cut-and-pack-for-woocommerce/tags/1.1.0/includes/class-cutpack-frontend.php
r3800171 r3805284 33 33 return $html; 34 34 } 35 $s = Cutpack_Settings::get( $product ); 35 $s = $product->is_type( 'variation' ) 36 ? Cutpack_Settings::get_for( $product->get_parent_id(), $product->get_id() ) 37 : Cutpack_Settings::get( $product ); 36 38 return $html . ' <span class="cutpack-per-unit">/ ' . esc_html( Cutpack_Settings::unit_label( $s['measure'] ) ) . '</span>'; 37 39 } … … 92 94 93 95 /** 96 * Per-variation data for the browser preview, keyed by variation ID. 97 * 98 * Built on the server so the preview never depends on theme markup or on 99 * WooCommerce's own variation scripts. 100 * 101 * @param WC_Product $product Variable product. 102 * @return array 103 */ 104 private static function variation_map( $product ) { 105 $map = array(); 106 if ( ! $product->is_type( 'variable' ) ) { 107 return $map; 108 } 109 110 /** 111 * Maximum number of variations sent to the browser preview. 112 * 113 * @param int $limit Limit. 114 */ 115 $limit = (int) apply_filters( 'cutpack_max_preview_variations', 500 ); 116 117 $children = array_slice( $product->get_children(), 0, $limit ); 118 if ( $children ) { 119 _prime_post_caches( $children, false, true ); 120 } 121 122 foreach ( $children as $variation_id ) { 123 $variation = wc_get_product( $variation_id ); 124 if ( ! $variation instanceof WC_Product_Variation || ! $variation->variation_is_visible() ) { 125 continue; 126 } 127 $vs = Cutpack_Settings::get_for( $product->get_id(), $variation->get_id() ); 128 $price = $variation->get_price(); 129 130 $map[ $variation->get_id() ] = array( 131 'coverage' => (float) $vs['coverage'], 132 'unitPrice' => '' === $price ? 0 : (float) wc_get_price_to_display( $variation ), 133 'purchasable' => '' !== $price && $variation->is_purchasable() && $variation->is_in_stock(), 134 'maxQty' => (int) $variation->get_max_purchase_quantity(), 135 ); 136 } 137 return $map; 138 } 139 140 /** 94 141 * Load the calculator script and its settings on enabled product pages. 95 142 */ … … 112 159 'cutpackData', 113 160 array( 114 'id' => 'cutpack-' . $product->get_id(), 115 'mode' => $s['mode'], 116 'measure' => $s['measure'], 117 'input' => $s['input'], 118 'coverage' => (float) $s['coverage'], 119 'min' => '' === $s['min'] ? 0 : (float) $s['min'], 120 'max' => '' === $s['max'] ? 0 : (float) $s['max'], 121 'step' => '' === $s['step'] ? 0 : (float) $s['step'], 122 'unitPrice' => (float) wc_get_price_to_display( $product ), 123 'unit' => Cutpack_Settings::unit_label( $s['measure'] ), 124 'currency' => array( 161 'id' => 'cutpack-' . $product->get_id(), 162 'mode' => $s['mode'], 163 'measure' => $s['measure'], 164 'input' => $s['input'], 165 'coverage' => (float) $s['coverage'], 166 'min' => '' === $s['min'] ? 0 : (float) $s['min'], 167 'max' => '' === $s['max'] ? 0 : (float) $s['max'], 168 'step' => '' === $s['step'] ? 0 : (float) $s['step'], 169 'unitPrice' => $product->is_type( 'variable' ) ? 0 : (float) wc_get_price_to_display( $product ), 170 'variable' => $product->is_type( 'variable' ), 171 'variations' => self::variation_map( $product ), 172 'unit' => Cutpack_Settings::unit_label( $s['measure'] ), 173 'currency' => array( 125 174 'symbol' => html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' ), 126 175 'format' => html_entity_decode( get_woocommerce_price_format(), ENT_QUOTES, 'UTF-8' ), … … 129 178 'thousands' => wc_get_price_thousand_separator(), 130 179 ), 131 'i18n' => array(180 'i18n' => array( 132 181 /* translators: 1: number of boxes, 2: amount, 3: unit, 4: price. Example: You need 17 boxes (24.48 m²) – £976.75 */ 133 'resultPacks' => __( 'You need %1$s (%2$s %3$s) – %4$s', 'cut-and-pack-for-woocommerce' ),182 'resultPacks' => __( 'You need %1$s (%2$s %3$s) – %4$s', 'cut-and-pack-for-woocommerce' ), 134 183 /* translators: 1: amount, 2: unit, 3: price. Example: 2.4 m – £43.20 */ 135 'resultCut' => __( '%1$s %2$s – %3$s', 'cut-and-pack-for-woocommerce' ),184 'resultCut' => __( '%1$s %2$s – %3$s', 'cut-and-pack-for-woocommerce' ), 136 185 /* translators: %s: a number */ 137 'oneBox' => __( '%s box', 'cut-and-pack-for-woocommerce' ),186 'oneBox' => __( '%s box', 'cut-and-pack-for-woocommerce' ), 138 187 /* translators: %s: a number */ 139 'manyBoxes' => __( '%s boxes', 'cut-and-pack-for-woocommerce' ), 140 'invalid' => __( 'Please enter a number greater than zero.', 'cut-and-pack-for-woocommerce' ), 141 'invalidSize' => __( 'Please enter a length and a width greater than zero.', 'cut-and-pack-for-woocommerce' ), 188 'manyBoxes' => __( '%s boxes', 'cut-and-pack-for-woocommerce' ), 189 'chooseOption' => __( 'Choose an option first.', 'cut-and-pack-for-woocommerce' ), 190 'unavailable' => __( 'This option is unavailable.', 'cut-and-pack-for-woocommerce' ), 191 /* translators: 1: number of boxes in stock, 2: amount covered, 3: unit such as m² */ 192 'stock' => __( 'Only %1$s in stock (%2$s %3$s).', 'cut-and-pack-for-woocommerce' ), 193 'invalid' => __( 'Please enter a number greater than zero.', 'cut-and-pack-for-woocommerce' ), 194 'invalidSize' => __( 'Please enter a length and a width greater than zero.', 'cut-and-pack-for-woocommerce' ), 142 195 /* translators: 1: minimum amount, 2: unit such as m² */ 143 'min' => __( 'The minimum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ),196 'min' => __( 'The minimum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ), 144 197 /* translators: 1: maximum amount, 2: unit such as m² */ 145 'max' => __( 'The maximum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ),198 'max' => __( 'The maximum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ), 146 199 ), 147 200 ) -
cut-and-pack-for-woocommerce/tags/1.1.0/includes/class-cutpack-settings.php
r3800171 r3805284 66 66 */ 67 67 public static function get( $product ) { 68 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 68 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 69 70 /** 71 * Filter a product's Cut & Pack settings. 72 * 73 * @param array $settings Settings. 74 * @param WC_Product|null $product Product (the parent for a variation). 75 * @param WC_Product_Variation|null $variation Variation, when settings are read for one. 76 */ 77 return apply_filters( 'cutpack_product_settings', self::read( $product ), $product, null ); 78 } 79 80 /** 81 * Settings stored on a product, cleaned but not filtered. 82 * 83 * @param WC_Product|null $product Product. 84 * @return array 85 */ 86 private static function read( $product ) { 69 87 $settings = self::defaults(); 70 88 … … 78 96 } 79 97 80 /** 81 * Filter a product's Cut & Pack settings. 82 * 83 * @param array $settings Settings. 84 * @param WC_Product|null $product Product. 85 */ 86 return apply_filters( 'cutpack_product_settings', self::normalise( $settings ), $product ); 98 return self::normalise( $settings ); 99 } 100 101 /** 102 * Settings for a product, or for one of its variations. 103 * 104 * A variation may override the pack coverage; everything else comes from 105 * the parent product. A variation that does not belong to the product is ignored. 106 * 107 * @param int $product_id Parent (or simple) product ID. 108 * @param int $variation_id Variation ID, or 0. 109 * @return array 110 */ 111 public static function get_for( $product_id, $variation_id = 0 ) { 112 $product = wc_get_product( absint( $product_id ) ); 113 if ( ! $product instanceof WC_Product ) { 114 return self::get( null ); 115 } 116 117 $variation = self::owned_variation( $product, $variation_id ); 118 if ( ! $variation ) { 119 return self::get( $product ); 120 } 121 122 $settings = self::read( $product ); 123 $override = self::to_positive_decimal( $variation->get_meta( self::meta_key( 'coverage' ), true ) ); 124 if ( '' !== $override && self::MODE_PACKS === $settings['mode'] && self::MEASURE_AREA === $settings['measure'] ) { 125 $settings['coverage'] = $override; 126 } 127 128 /** This filter is documented in get(). */ 129 return apply_filters( 'cutpack_product_settings', self::normalise( $settings ), $product, $variation ); 130 } 131 132 /** 133 * The variation with this ID, but only if it really belongs to the product. 134 * 135 * @param WC_Product $product Parent product. 136 * @param int $variation_id Variation ID. 137 * @return WC_Product_Variation|null 138 */ 139 public static function owned_variation( $product, $variation_id ) { 140 $variation_id = absint( $variation_id ); 141 if ( ! $variation_id || ! $product instanceof WC_Product || ! $product->is_type( 'variable' ) ) { 142 return null; 143 } 144 $variation = wc_get_product( $variation_id ); 145 if ( $variation instanceof WC_Product && $variation->is_type( 'variation' ) && (int) $variation->get_parent_id() === (int) $product->get_id() ) { 146 return $variation; 147 } 148 return null; 87 149 } 88 150 … … 90 152 * Whether the calculator is switched on for a product. 91 153 * 92 * Version 1 supports simple products only. 154 * Works for simple and variable products. A variation counts as enabled 155 * when its parent is. 93 156 * 94 157 * @param WC_Product|int $product Product or product ID. … … 97 160 public static function is_enabled( $product ) { 98 161 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 99 if ( ! $product instanceof WC_Product || ! $product->is_type( 'simple' ) ) { 162 if ( $product instanceof WC_Product && $product->is_type( 'variation' ) ) { 163 $product = wc_get_product( $product->get_parent_id() ); 164 } 165 if ( ! $product instanceof WC_Product || ! ( $product->is_type( 'simple' ) || $product->is_type( 'variable' ) ) ) { 100 166 return false; 101 167 } -
cut-and-pack-for-woocommerce/tags/1.1.0/languages/cut-and-pack-for-woocommerce.pot
r3800171 r3805284 1 # Copyright (C) 2026 C ut & Pack1 # Copyright (C) 2026 Cartwright 2 2 # This file is distributed under the GPL-2.0-or-later. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Cut & Pack for WooCommerce 0.1.0\n"5 "Project-Id-Version: Cut & Pack for WooCommerce 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cut-and-pack-for-woocommerce\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 0-29T17:11:31+00:00\n"12 "POT-Creation-Date: 2026-11-13T09:29:09+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 27 27 #. Author of the plugin 28 28 #: cut-and-pack-for-woocommerce.php 29 #: includes/class-cutpack-admin.php:39 29 msgid "Cartwright" 30 msgstr "" 31 32 #. Author URI of the plugin 33 #: cut-and-pack-for-woocommerce.php 34 msgid "https://cartwrightplugins.com/" 35 msgstr "" 36 37 #: includes/class-cutpack-admin.php:41 30 38 msgid "Cut & Pack" 31 39 msgstr "" 32 40 33 #: includes/class-cutpack-admin.php:4 141 #: includes/class-cutpack-admin.php:43 34 42 msgid "Switch the calculator on for each product in its \"Made to measure\" tab." 35 43 msgstr "" 36 44 37 #: includes/class-cutpack-admin.php:4 545 #: includes/class-cutpack-admin.php:47 38 46 msgid "Remove data on uninstall" 39 47 msgstr "" 40 48 41 #: includes/class-cutpack-admin.php:4 649 #: includes/class-cutpack-admin.php:48 42 50 msgid "Delete all Cut & Pack product settings when the plugin is deleted. Measurements on past orders are always kept." 43 51 msgstr "" 44 52 45 #: includes/class-cutpack-admin.php:6 653 #: includes/class-cutpack-admin.php:68 46 54 msgid "Settings" 47 55 msgstr "" 48 56 49 #: includes/class-cutpack-admin.php: 7857 #: includes/class-cutpack-admin.php:80 50 58 msgid "Made to measure" 51 59 msgstr "" 52 60 53 #: includes/class-cutpack-admin.php:10 261 #: includes/class-cutpack-admin.php:104 54 62 msgid "Enable calculator" 55 63 msgstr "" 56 64 57 #: includes/class-cutpack-admin.php:10 365 #: includes/class-cutpack-admin.php:105 58 66 msgid "Shoppers enter a size instead of a quantity, and the price is calculated for them." 59 67 msgstr "" 60 68 61 #: includes/class-cutpack-admin.php:11 269 #: includes/class-cutpack-admin.php:114 62 70 msgid "Mode" 63 71 msgstr "" 64 72 65 #: includes/class-cutpack-admin.php:11 473 #: includes/class-cutpack-admin.php:116 66 74 msgid "Sold in packs (e.g. tiles, flooring)" 67 75 msgstr "" 68 76 69 #: includes/class-cutpack-admin.php:11 577 #: includes/class-cutpack-admin.php:117 70 78 msgid "Cut to size (e.g. fabric, blinds)" 71 79 msgstr "" 72 80 73 #: includes/class-cutpack-admin.php:1 1981 #: includes/class-cutpack-admin.php:121 74 82 msgid "Packs: the order is rounded up to whole boxes. Cut to size: the shopper pays for exactly the amount entered." 75 83 msgstr "" 76 84 77 #: includes/class-cutpack-admin.php:12 685 #: includes/class-cutpack-admin.php:128 78 86 msgid "Sold by" 79 87 msgstr "" 80 88 81 #: includes/class-cutpack-admin.php:1 2889 #: includes/class-cutpack-admin.php:130 82 90 msgid "Area (m²)" 83 91 msgstr "" 84 92 85 #: includes/class-cutpack-admin.php:1 2993 #: includes/class-cutpack-admin.php:131 86 94 msgid "Length (m)" 87 95 msgstr "" 88 96 89 #: includes/class-cutpack-admin.php:1 3897 #: includes/class-cutpack-admin.php:140 90 98 msgid "Shopper enters" 91 99 msgstr "" 92 100 93 #: includes/class-cutpack-admin.php:14 0101 #: includes/class-cutpack-admin.php:142 94 102 msgid "Total area" 95 103 msgstr "" 96 104 97 #: includes/class-cutpack-admin.php:14 1105 #: includes/class-cutpack-admin.php:143 98 106 msgid "Length × width" 99 107 msgstr "" 100 108 101 #: includes/class-cutpack-admin.php:149 109 #: includes/class-cutpack-admin.php:152 110 msgid "The price comes from each variation's own Regular price, read as a price per m² or per metre." 111 msgstr "" 112 113 #: includes/class-cutpack-admin.php:154 102 114 msgid "The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre." 103 115 msgstr "" 104 116 105 117 #. translators: %s: unit, e.g. m² 106 #: includes/class-cutpack-admin.php:1 58118 #: includes/class-cutpack-admin.php:164 107 119 #, php-format 108 120 msgid "Coverage per pack (%s)" 109 121 msgstr "" 110 122 111 #: includes/class-cutpack-admin.php:16 3123 #: includes/class-cutpack-admin.php:169 112 124 msgid "How much one box covers. Stock is counted in boxes." 113 125 msgstr "" 114 126 115 127 #. translators: %s: unit, e.g. m² 116 #: includes/class-cutpack-admin.php:17 2128 #: includes/class-cutpack-admin.php:178 117 129 #, php-format 118 130 msgid "Minimum (%s)" 119 131 msgstr "" 120 132 121 #: includes/class-cutpack-admin.php:1 76133 #: includes/class-cutpack-admin.php:182 122 134 msgid "Smallest amount a shopper can order. Leave empty for no minimum." 123 135 msgstr "" 124 136 125 137 #. translators: %s: unit, e.g. m² 126 #: includes/class-cutpack-admin.php:1 84138 #: includes/class-cutpack-admin.php:190 127 139 #, php-format 128 140 msgid "Maximum (%s)" 129 141 msgstr "" 130 142 131 #: includes/class-cutpack-admin.php:1 88143 #: includes/class-cutpack-admin.php:194 132 144 msgid "Largest amount a shopper can order. Leave empty for no maximum." 133 145 msgstr "" 134 146 135 147 #. translators: %s: unit, e.g. m 136 #: includes/class-cutpack-admin.php: 196148 #: includes/class-cutpack-admin.php:202 137 149 #, php-format 138 150 msgid "Step (%s)" 139 151 msgstr "" 140 152 141 #: includes/class-cutpack-admin.php:20 1153 #: includes/class-cutpack-admin.php:207 142 154 msgid "Amounts are rounded up to this step, e.g. 0.1 turns 2.34 into 2.4." 143 155 msgstr "" 144 156 145 #: includes/class-cutpack-admin.php:2 09157 #: includes/class-cutpack-admin.php:215 146 158 msgid "Label text" 147 159 msgstr "" 148 160 149 #: includes/class-cutpack-admin.php:21 1150 #: includes/class-cutpack-frontend.php: 59161 #: includes/class-cutpack-admin.php:217 162 #: includes/class-cutpack-frontend.php:61 151 163 msgid "How many m² do you need?" 152 164 msgstr "" 153 165 154 #: includes/class-cutpack-admin.php:21 3166 #: includes/class-cutpack-admin.php:219 155 167 msgid "Optional wording shown above the calculator." 156 168 msgstr "" 157 169 158 #: includes/class-cutpack-admin.php:273 170 #. translators: %s: unit 171 #: includes/class-cutpack-admin.php:246 172 #, php-format 173 msgid "Pack size: coverage per pack (%s)" 174 msgstr "" 175 176 #: includes/class-cutpack-admin.php:248 177 msgid "Same as the product" 178 msgstr "" 179 180 #: includes/class-cutpack-admin.php:249 181 msgid "Only for packs. Leave empty to use the number from the \"Made to measure\" tab." 182 msgstr "" 183 184 #: includes/class-cutpack-admin.php:319 159 185 msgid "Enter how much one pack covers." 160 186 msgstr "" 161 187 162 #: includes/class-cutpack-admin.php: 277188 #: includes/class-cutpack-admin.php:323 163 189 msgid "The minimum is larger than the maximum." 164 190 msgstr "" 165 191 166 #: includes/class-cutpack-admin.php: 281192 #: includes/class-cutpack-admin.php:328 167 193 msgid "Enter a Regular price on the General tab (price per m² or per metre)." 168 194 msgstr "" 169 195 170 #: includes/class-cutpack-admin.php: 287196 #: includes/class-cutpack-admin.php:334 171 197 msgid "Cut & Pack: the calculator was switched off for this product." 172 198 msgstr "" 173 199 174 200 #: includes/class-cutpack-calculator.php:45 175 #: includes/class-cutpack-frontend.php:1 41201 #: includes/class-cutpack-frontend.php:194 176 202 msgid "Please enter a length and a width greater than zero." 177 203 msgstr "" … … 183 209 #. translators: 1: minimum amount, 2: unit such as m² 184 210 #: includes/class-cutpack-calculator.php:61 185 #: includes/class-cutpack-frontend.php:1 43211 #: includes/class-cutpack-frontend.php:196 186 212 #, php-format 187 213 msgid "The minimum is %1$s %2$s." … … 190 216 #. translators: 1: maximum amount, 2: unit such as m² 191 217 #: includes/class-cutpack-calculator.php:69 192 #: includes/class-cutpack-frontend.php:1 45218 #: includes/class-cutpack-frontend.php:198 193 219 #, php-format 194 220 msgid "The maximum is %1$s %2$s." … … 199 225 msgstr "" 200 226 227 #: includes/class-cutpack-cart.php:135 228 #: includes/class-cutpack-frontend.php:189 229 msgid "Choose an option first." 230 msgstr "" 231 201 232 #. translators: %s: product name 202 #: includes/class-cutpack-cart.php:2 06233 #: includes/class-cutpack-cart.php:282 203 234 #, php-format 204 235 msgid "%s was removed from your cart. Please enter the size you need on the product page and add it again." 205 236 msgstr "" 206 237 207 #: includes/class-cutpack-cart.php: 227238 #: includes/class-cutpack-cart.php:303 208 239 msgid "Coverage" 209 240 msgstr "" 210 241 211 242 #. translators: 1: amount, 2: unit, 3: number of boxes. Example: 24.48 m² (17 boxes) 212 #: includes/class-cutpack-cart.php: 230243 #: includes/class-cutpack-cart.php:306 213 244 #, php-format 214 245 msgid "%1$s %2$s (%3$s box)" … … 217 248 msgstr[1] "" 218 249 219 #: includes/class-cutpack-cart.php: 238220 #: includes/class-cutpack-cart.php: 246250 #: includes/class-cutpack-cart.php:314 251 #: includes/class-cutpack-cart.php:322 221 252 msgid "You entered" 222 253 msgstr "" 223 254 224 #: includes/class-cutpack-cart.php: 242255 #: includes/class-cutpack-cart.php:318 225 256 msgid "Length" 226 257 msgstr "" 227 258 228 #: includes/class-cutpack-cart.php: 242259 #: includes/class-cutpack-cart.php:318 229 260 msgid "Area" 230 261 msgstr "" 231 262 232 263 #. translators: abbreviation for metres 233 #: includes/class-cutpack-cart.php: 267234 #: includes/class-cutpack-settings.php: 171264 #: includes/class-cutpack-cart.php:343 265 #: includes/class-cutpack-settings.php:237 235 266 msgid "m" 236 267 msgstr "" 237 268 238 #: includes/class-cutpack-cart.php: 346269 #: includes/class-cutpack-cart.php:422 239 270 msgid "Enter size" 240 271 msgstr "" 241 272 242 #: includes/class-cutpack-frontend.php:5 5273 #: includes/class-cutpack-frontend.php:57 243 274 msgid "Enter the size of your area" 244 275 msgstr "" 245 276 246 #: includes/class-cutpack-frontend.php:5 7277 #: includes/class-cutpack-frontend.php:59 247 278 msgid "How many metres do you need?" 248 279 msgstr "" 249 280 250 281 #. translators: %s: unit 251 #: includes/class-cutpack-frontend.php:7 1282 #: includes/class-cutpack-frontend.php:73 252 283 #, php-format 253 284 msgid "Length (%s)" … … 255 286 256 287 #. translators: %s: unit 257 #: includes/class-cutpack-frontend.php:7 6288 #: includes/class-cutpack-frontend.php:78 258 289 #, php-format 259 290 msgid "Width (%s)" … … 261 292 262 293 #. translators: 1: number of boxes, 2: amount, 3: unit, 4: price. Example: You need 17 boxes (24.48 m²) – £976.75 263 #: includes/class-cutpack-frontend.php:1 33294 #: includes/class-cutpack-frontend.php:182 264 295 #, php-format 265 296 msgid "You need %1$s (%2$s %3$s) – %4$s" … … 267 298 268 299 #. translators: 1: amount, 2: unit, 3: price. Example: 2.4 m – £43.20 269 #: includes/class-cutpack-frontend.php:1 35300 #: includes/class-cutpack-frontend.php:184 270 301 #, php-format 271 302 msgid "%1$s %2$s – %3$s" … … 273 304 274 305 #. translators: %s: a number 275 #: includes/class-cutpack-frontend.php:1 37306 #: includes/class-cutpack-frontend.php:186 276 307 #, php-format 277 308 msgid "%s box" … … 279 310 280 311 #. translators: %s: a number 281 #: includes/class-cutpack-frontend.php:1 39312 #: includes/class-cutpack-frontend.php:188 282 313 #, php-format 283 314 msgid "%s boxes" 284 315 msgstr "" 285 316 286 #: includes/class-cutpack-frontend.php:140 317 #: includes/class-cutpack-frontend.php:190 318 msgid "This option is unavailable." 319 msgstr "" 320 321 #. translators: 1: number of boxes in stock, 2: amount covered, 3: unit such as m² 322 #: includes/class-cutpack-frontend.php:192 323 #, php-format 324 msgid "Only %1$s in stock (%2$s %3$s)." 325 msgstr "" 326 327 #: includes/class-cutpack-frontend.php:193 287 328 msgid "Please enter a number greater than zero." 288 329 msgstr "" 289 330 290 331 #. translators: abbreviation for square metres 291 #: includes/class-cutpack-settings.php: 173332 #: includes/class-cutpack-settings.php:239 292 333 msgid "m²" 293 334 msgstr "" -
cut-and-pack-for-woocommerce/tags/1.1.0/readme.txt
r3800171 r3805284 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 47 47 1. Install and activate WooCommerce. 48 48 2. Go to Plugins → Add New, search for "Cut & Pack", then install and activate it. 49 3. Edit a simple product. On the General tab, enter the price per m² (or per metre) as the Regular price.49 3. Edit a simple or variable product and enter the price per m² (or per metre) as the Regular price (on a variable product, on each variation). 50 50 4. Open the new "Made to measure" tab, tick "Enable calculator" and choose the mode. 51 51 5. For packs, enter how much one box covers (for example 1.44 m²). … … 56 56 = Which product types are supported? = 57 57 58 Simple products. Support for variable products (for example one floor in several finishes) is planned. 58 Simple and variable products. On a variable product (for example one floor in several finishes) each variation has its own price per m², its own stock and, if you like, its own pack size. Grouped and external products are not supported. 59 60 = Can each variation have a different pack size? = 61 62 Yes. Switch the calculator on in the product's "Made to measure" tab and enter the usual pack size. In each variation's panel you can enter a different "Pack size"; leave it empty to use the product's. Stock is counted in boxes, so if a finish has 5 boxes left the shopper is told so instead of being able to order more. 63 64 = What does "Order again" do with measured items? = 65 66 Measured items are not added again automatically, because the size has to be entered again. The shopper opens the product page and enters the size. 59 67 60 68 = What price do I enter? = … … 94 102 == Changelog == 95 103 104 = 1.1.0 = 105 * New: variable products. Each variation can have its own price per m² (or per metre), its own stock and, optionally, its own pack size. 106 * New: a finish that has only a few boxes left tells the shopper how many boxes can be ordered. 107 * Developers: the `cutpack_product_settings` filter now receives the parent product as its second argument and, for a variation, the variation as a third argument. 108 96 109 = 1.0.0 = 97 110 * First release. … … 99 112 == Upgrade Notice == 100 113 114 = 1.1.0 = 115 Adds support for variable products (different price, stock and pack size per variation). 116 101 117 = 1.0.0 = 102 118 First release. -
cut-and-pack-for-woocommerce/trunk/assets/js/admin.js
r3800171 r3805284 13 13 14 14 $( panel + ' .cutpack-show-if-packs' ).toggle( 'packs' === mode ); 15 $( '.cutpack-variation-field' ).toggle( 'packs' === mode && 'area' === measure ); 15 16 $( panel + ' .cutpack-show-if-cut' ).toggle( 'cut' === mode ); 16 17 $( panel + ' .cutpack-show-if-area' ).toggle( 'area' === measure ); … … 27 28 $( function () { 28 29 $( document ).on( 'change', '#_cutpack_mode, #_cutpack_measure', refresh ); 30 $( document ).on( 'woocommerce_variations_loaded woocommerce_variations_added', refresh ); 29 31 refresh(); 30 32 } ); -
cut-and-pack-for-woocommerce/trunk/assets/js/calculator.js
r3800171 r3805284 19 19 return; 20 20 } 21 var form = box.closest( 'form .cart' );21 var form = box.closest( 'form' ); 22 22 if ( ! form ) { 23 23 return; … … 25 25 26 26 var qty = form.querySelector( 'input[name="quantity"]' ); 27 var button = form.querySelector( ' .single_add_to_cart_button' );27 var button = form.querySelector( '[type="submit"], .single_add_to_cart_button' ); 28 28 var inputs = box.querySelectorAll( '.cutpack-input' ); 29 29 var resultEl = box.querySelector( '.cutpack-result' ); … … 68 68 } 69 69 70 function calculate() { 70 /** 71 * What applies right now: the product itself, or the chosen variation. 72 * The variation id is read from the form every time, never cached. 73 */ 74 function current() { 75 if ( ! d.variable ) { 76 return { ok: true, coverage: d.coverage, unitPrice: d.unitPrice, maxQty: -1 }; 77 } 78 var field = form.querySelector( 'input[name="variation_id"]' ); 79 var id = field ? parseInt( field.value, 10 ) || 0 : 0; 80 if ( ! id ) { 81 return { ok: false, id: 0, message: d.i18n.chooseOption }; 82 } 83 var v = d.variations[ id ]; 84 if ( ! v || ! v.purchasable ) { 85 return { ok: false, id: id, message: d.i18n.unavailable }; 86 } 87 return { ok: true, id: id, coverage: v.coverage, unitPrice: v.unitPrice, maxQty: v.maxQty }; 88 } 89 90 function calculate( cur ) { 71 91 var entered; 72 92 … … 93 113 94 114 if ( 'packs' === d.mode ) { 95 var packs = Math.max( 1, Math.ceil( entered / d.coverage - EPSILON ) );96 var charged = round( packs * d.coverage, 6 );115 var packs = Math.max( 1, Math.ceil( entered / cur.coverage - EPSILON ) ); 116 var charged = round( packs * cur.coverage, 6 ); 97 117 // Price of one box is rounded to whole pennies first, as on the server. 98 var boxPrice = round( d.coverage * d.unitPrice, d.currency.decimals ); 118 var boxPrice = round( cur.coverage * cur.unitPrice, d.currency.decimals ); 119 if ( cur.maxQty >= 0 && packs > cur.maxQty ) { 120 var inStock = format( 1 === cur.maxQty ? d.i18n.oneBox : d.i18n.manyBoxes, cur.maxQty ); 121 return { error: format( d.i18n.stock, inStock, formatAmount( cur.maxQty * cur.coverage ), d.unit ) }; 122 } 99 123 return { packs: packs, charged: charged, price: packs * boxPrice }; 100 124 } 101 125 102 126 var amount = d.step > 0 ? round( Math.ceil( entered / d.step - EPSILON ) * d.step, 6 ) : entered; 103 return { packs: 1, charged: amount, price: round( amount * d.unitPrice, d.currency.decimals ) };127 return { packs: 1, charged: amount, price: round( amount * cur.unitPrice, d.currency.decimals ) }; 104 128 } 105 129 … … 121 145 } 122 146 147 /** Write only when the text changes, so screen readers don't repeat themselves. */ 148 function setText( el, text ) { 149 if ( el.textContent !== text ) { 150 el.textContent = text; 151 } 152 } 153 154 /** The quantity box is hidden, so the browser must never block the form over it. */ 155 function relaxQuantity() { 156 if ( qty ) { 157 qty.removeAttribute( 'min' ); 158 qty.removeAttribute( 'max' ); 159 qty.removeAttribute( 'step' ); 160 } 161 } 162 163 /** The calculator replaces the normal quantity box. WooCommerce may show it again, so hide it on every update. */ 164 function hideQuantity() { 165 var wrap = qty && button ? qty.closest( '.quantity' ) : null; 166 if ( wrap ) { 167 wrap.style.setProperty( 'display', 'none', 'important' ); 168 } 169 } 170 123 171 function update() { 172 hideQuantity(); 173 var cur = current(); 174 if ( ! cur.ok ) { 175 setText( resultEl, cur.message ); 176 setText( errorEl, '' ); 177 setButton( false ); 178 return; 179 } 180 124 181 if ( isEmpty() ) { 125 resultEl.textContent = '';126 errorEl.textContent = '';127 setButton( false ); 128 return; 129 } 130 131 var r = calculate( );182 setText( resultEl, '' ); 183 setText( errorEl, '' ); 184 setButton( false ); 185 return; 186 } 187 188 var r = calculate( cur ); 132 189 133 190 if ( r.error ) { 134 resultEl.textContent = '';135 errorEl.textContent = r.error;136 setButton( false ); 137 return; 138 } 139 140 errorEl.textContent = '';191 setText( resultEl, '' ); 192 setText( errorEl, r.error ); 193 setButton( false ); 194 return; 195 } 196 197 setText( errorEl, '' ); 141 198 142 199 if ( 'packs' === d.mode ) { 143 200 var boxes = format( 1 === r.packs ? d.i18n.oneBox : d.i18n.manyBoxes, r.packs ); 144 resultEl.textContent = format( d.i18n.resultPacks, boxes, formatAmount( r.charged ), d.unit, formatPrice( r.price) );201 setText( resultEl, format( d.i18n.resultPacks, boxes, formatAmount( r.charged ), d.unit, formatPrice( r.price ) ) ); 145 202 if ( qty ) { 146 203 qty.value = r.packs; 147 204 } 148 205 } else { 149 resultEl.textContent = format( d.i18n.resultCut, formatAmount( r.charged ), d.unit, formatPrice( r.price) );206 setText( resultEl, format( d.i18n.resultCut, formatAmount( r.charged ), d.unit, formatPrice( r.price ) ) ); 150 207 if ( qty ) { 151 208 qty.value = 1; … … 153 210 } 154 211 212 relaxQuantity(); 155 213 setButton( true ); 156 214 } 157 215 158 // The calculator replaces the normal quantity box. 159 if ( qty ) { 160 var wrap = qty.closest( '.quantity' ); 161 if ( wrap ) { 162 wrap.style.display = 'none'; 163 } 216 /** Re-run after WooCommerce (or the block) has finished its own changes. */ 217 function later() { 218 window.setTimeout( function () { 219 update(); 220 if ( window.requestAnimationFrame ) { 221 window.requestAnimationFrame( update ); 222 } 223 }, 0 ); 164 224 } 165 225 … … 168 228 } 169 229 230 if ( d.variable ) { 231 // Any interaction with the form may change the chosen variation. 232 [ 'click', 'change', 'input', 'keyup' ].forEach( function ( name ) { 233 form.addEventListener( name, later ); 234 } ); 235 236 // WooCommerce's own events, when jQuery is on the page. 237 if ( window.jQuery ) { 238 window.jQuery( form ).on( 'found_variation show_variation hide_variation reset_data check_variations', later ); 239 } 240 241 // Backstop for themes that change the chosen option without any event. 242 var lastId = null; 243 window.setInterval( function () { 244 var now = current(); 245 var key = String( now.id || 0 ) + ( now.ok ? '1' : '0' ); 246 if ( key !== lastId ) { 247 lastId = key; 248 update(); 249 } 250 }, 250 ); 251 } 252 253 // Drop the hidden quantity's limits just before the browser checks the form. 254 if ( button ) { 255 button.addEventListener( 'click', relaxQuantity, true ); 256 } 257 170 258 // Stop the form being sent with an invalid size (e.g. by pressing Enter). 171 259 form.addEventListener( 'submit', function ( event ) { 172 var r = isEmpty() ? { error: d.i18n.invalid } : calculate(); 260 var cur = current(); 261 var r = ! cur.ok ? { error: cur.message } : ( isEmpty() ? { error: d.i18n.invalid } : calculate( cur ) ); 262 relaxQuantity(); 173 263 if ( r.error ) { 174 264 event.preventDefault(); 175 errorEl.textContent = r.error;265 setText( errorEl, r.error ); 176 266 setButton( false ); 177 267 } -
cut-and-pack-for-woocommerce/trunk/cut-and-pack-for-woocommerce.php
r3800171 r3805284 3 3 * Plugin Name: Cut & Pack for WooCommerce 4 4 * Description: Made-to-measure pricing for WooCommerce. Sell by m² or metre, round up to whole packs, and show the price live. 5 * Version: 1. 0.05 * Version: 1.1.0 6 6 * Requires at least: 6.9 7 7 * Requires PHP: 7.4 … … 21 21 defined( 'ABSPATH' ) || exit; 22 22 23 define( 'CUTPACK_VERSION', '1. 0.0' );23 define( 'CUTPACK_VERSION', '1.1.0' ); 24 24 define( 'CUTPACK_FILE', __FILE__ ); 25 25 define( 'CUTPACK_PATH', plugin_dir_path( __FILE__ ) ); -
cut-and-pack-for-woocommerce/trunk/includes/class-cutpack-admin.php
r3800171 r3805284 20 20 add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'render_panel' ) ); 21 21 add_action( 'woocommerce_admin_process_product_object', array( __CLASS__, 'save' ) ); 22 add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'render_variation_field' ), 10, 3 ); 23 add_action( 'woocommerce_admin_process_variation_object', array( __CLASS__, 'save_variation' ), 10, 2 ); 22 24 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ) ); 23 25 add_filter( 'woocommerce_get_settings_products', array( __CLASS__, 'store_settings' ), 10, 2 ); … … 78 80 'label' => __( 'Made to measure', 'cut-and-pack-for-woocommerce' ), 79 81 'target' => 'cutpack_product_data', 80 'class' => array( 'show_if_simple', ' hide_if_variable', 'hide_if_grouped', 'hide_if_external' ),82 'class' => array( 'show_if_simple', 'show_if_variable', 'hide_if_grouped', 'hide_if_external' ), 81 83 'priority' => 65, 82 84 ); … … 147 149 148 150 echo '<p class="form-field cutpack-price-note"><span class="description">'; 149 echo esc_html__( 'The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 151 if ( $product_object instanceof WC_Product && $product_object->is_type( 'variable' ) ) { 152 echo esc_html__( 'The price comes from each variation\'s own Regular price, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 153 } else { 154 echo esc_html__( 'The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre.', 'cut-and-pack-for-woocommerce' ); 155 } 150 156 echo '</span></p>'; 151 157 … … 227 233 228 234 /** 235 * Optional per-variation pack size, shown in each variation's panel. 236 * 237 * @param int $loop Position in the loop. 238 * @param array $variation_data Variation data. 239 * @param WP_Post $variation Variation post. 240 */ 241 public static function render_variation_field( $loop, $variation_data, $variation ) { 242 $value = get_post_meta( $variation->ID, Cutpack_Settings::meta_key( 'coverage' ), true ); 243 ?> 244 <div class="cutpack-variation-field form-row form-row-full"> 245 <label for="cutpack_variation_coverage_<?php echo esc_attr( $loop ); ?>"> 246 <?php echo esc_html( sprintf( /* translators: %s: unit */ __( 'Pack size: coverage per pack (%s)', 'cut-and-pack-for-woocommerce' ), Cutpack_Settings::unit_label( Cutpack_Settings::MEASURE_AREA ) ) ); ?> 247 </label> 248 <input type="text" inputmode="decimal" class="short" id="cutpack_variation_coverage_<?php echo esc_attr( $loop ); ?>" name="cutpack_variation_coverage[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr__( 'Same as the product', 'cut-and-pack-for-woocommerce' ); ?>" /> 249 <span class="description"><?php esc_html_e( 'Only for packs. Leave empty to use the number from the "Made to measure" tab.', 'cut-and-pack-for-woocommerce' ); ?></span> 250 </div> 251 <?php 252 } 253 254 /** 255 * Save the per-variation pack size. WooCommerce has already checked the nonce. 256 * 257 * @param WC_Product_Variation $variation Variation being saved. 258 * @param int $i Position in the posted list. 259 */ 260 public static function save_variation( $variation, $i ) { 261 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce checked by WooCommerce before this hook runs. 262 if ( ! isset( $_POST['cutpack_variation_coverage'][ $i ] ) || is_array( $_POST['cutpack_variation_coverage'][ $i ] ) ) { 263 return; 264 } 265 $raw = sanitize_text_field( wp_unslash( $_POST['cutpack_variation_coverage'][ $i ] ) ); 266 // phpcs:enable 267 268 if ( ! current_user_can( 'edit_post', $variation->get_parent_id() ) ) { 269 return; 270 } 271 $variation->update_meta_data( Cutpack_Settings::meta_key( 'coverage' ), Cutpack_Settings::to_positive_decimal( $raw ) ); 272 } 273 274 /** 229 275 * Save the tab's fields. WooCommerce has already checked the nonce and permissions. 230 276 * … … 278 324 } 279 325 280 if ( '' === $product->get_regular_price() ) { 326 // A variable product keeps its prices on the variations. 327 if ( ! $product->is_type( 'variable' ) && '' === $product->get_regular_price() ) { 281 328 $problems[] = __( 'Enter a Regular price on the General tab (price per m² or per metre).', 'cut-and-pack-for-woocommerce' ); 282 329 } -
cut-and-pack-for-woocommerce/trunk/includes/class-cutpack-cart.php
r3800171 r3805284 35 35 36 36 /** 37 * Variation chosen for each product during this add-to-cart request, as 38 * seen by the validation filter (which WooCommerce gives the variation, 39 * even when the form only posted attributes). 40 * 41 * @var int[] 42 */ 43 private static $chosen = array(); 44 45 /** 37 46 * Register hooks. 38 47 */ 39 48 public static function init() { 40 add_filter( 'woocommerce_add_to_cart_validation', array( __CLASS__, 'validate' ), 10, 2 ); 41 add_filter( 'woocommerce_add_to_cart_quantity', array( __CLASS__, 'quantity' ), 10, 2 ); 42 add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_item_data' ), 10, 2 ); 43 49 add_filter( 'woocommerce_add_to_cart_validation', array( __CLASS__, 'validate' ), 10, 4 ); 50 add_filter( 'woocommerce_add_to_cart_quantity', array( __CLASS__, 'quantity' ), 10, 3 ); 51 add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_item_data' ), 10, 3 ); 52 53 add_filter( 'woocommerce_add_cart_item', array( __CLASS__, 'lock_quantity' ), 15 ); 44 54 add_filter( 'woocommerce_add_cart_item', array( __CLASS__, 'apply_price' ), 20 ); 45 55 add_filter( 'woocommerce_get_cart_item_from_session', array( __CLASS__, 'apply_price' ), 20 ); … … 75 85 76 86 /** 87 * Work out the parent product and variation being added. 88 * 89 * WooCommerce passes the variation ID to some filters but not all, and 90 * `?add-to-cart=<variation id>` passes the variation as the product. 91 * Every server path resolves it here so they cannot disagree. 92 * 93 * @param int $product_id Product ID as received by the filter. 94 * @param int $variation_id Variation ID as received by the filter, or 0. 95 * @return int[] array( product ID, variation ID ). 96 */ 97 private static function resolve_ids( $product_id, $variation_id = 0 ) { 98 $product_id = absint( $product_id ); 99 $variation_id = absint( $variation_id ); 100 101 $product = wc_get_product( $product_id ); 102 if ( $product instanceof WC_Product && $product->is_type( 'variation' ) ) { 103 return array( (int) $product->get_parent_id(), $product_id ); 104 } 105 106 if ( ! $variation_id && isset( self::$chosen[ $product_id ] ) ) { 107 return array( $product_id, self::$chosen[ $product_id ] ); 108 } 109 110 if ( ! $variation_id && isset( $_REQUEST['variation_id'] ) && is_scalar( $_REQUEST['variation_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- WooCommerce add-to-cart forms carry no nonce; the ID is only used after checking it belongs to the product. 111 $variation_id = absint( wp_unslash( $_REQUEST['variation_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended 112 } 113 114 return array( $product_id, $variation_id ); 115 } 116 117 /** 77 118 * Calculate the posted input for a product. 78 119 * 79 * @param int $product_id Product ID. 120 * @param int $product_id Product ID. 121 * @param int $variation_id Variation ID, or 0. 80 122 * @return array|WP_Error|null Null if the product doesn't use the calculator. 81 123 */ 82 private static function posted_result( $product_id ) { 124 private static function posted_result( $product_id, $variation_id = 0 ) { 125 list( $product_id, $variation_id ) = self::resolve_ids( $product_id, $variation_id ); 126 83 127 $product = wc_get_product( $product_id ); 84 128 if ( ! Cutpack_Settings::is_enabled( $product ) ) { 85 129 return null; 86 130 } 87 return Cutpack_Calculator::calculate( Cutpack_Settings::get( $product ), self::posted_input() ); 131 132 if ( $product->is_type( 'variable' ) ) { 133 $variation = Cutpack_Settings::owned_variation( $product, $variation_id ); 134 if ( ! $variation ) { 135 return new WP_Error( 'cutpack_variation', __( 'Choose an option first.', 'cut-and-pack-for-woocommerce' ) ); 136 } 137 } 138 139 return Cutpack_Calculator::calculate( Cutpack_Settings::get_for( $product_id, $variation_id ), self::posted_input() ); 88 140 } 89 141 … … 91 143 * Block adding a measured product without a valid size. 92 144 * 93 * @param bool $passed Whether earlier checks passed. 94 * @param int $product_id Product ID. 145 * @param bool $passed Whether earlier checks passed. 146 * @param int $product_id Product ID. 147 * @param int $quantity Quantity (unused). 148 * @param int $variation_id Variation ID. 95 149 * @return bool 96 150 */ 97 public static function validate( $passed, $product_id ) { 98 $result = self::posted_result( $product_id ); 151 public static function validate( $passed, $product_id, $quantity = 1, $variation_id = 0 ) { 152 if ( absint( $variation_id ) ) { 153 self::$chosen[ absint( $product_id ) ] = absint( $variation_id ); 154 } 155 $result = self::posted_result( $product_id, $variation_id ); 99 156 if ( null === $result || ! $passed ) { 100 157 return $passed; … … 111 168 * whatever quantity the browser sent. 112 169 * 113 * @param int $quantity Quantity sent. 114 * @param int $product_id Product ID. 170 * @param int $quantity Quantity sent. 171 * @param int $product_id Product ID. 172 * @param int $variation_id Variation ID. 115 173 * @return int 116 174 */ 117 public static function quantity( $quantity, $product_id ) {118 $result = self::posted_result( $product_id );175 public static function quantity( $quantity, $product_id, $variation_id = 0 ) { 176 $result = self::posted_result( $product_id, $variation_id ); 119 177 if ( null === $result || is_wp_error( $result ) ) { 120 178 return $quantity; … … 126 184 * Store the measurements on the cart item. 127 185 * 128 * @param array $data Cart item data. 129 * @param int $product_id Product ID. 186 * @param array $data Cart item data. 187 * @param int $product_id Product ID. 188 * @param int $variation_id Variation ID. 130 189 * @return array 131 190 */ 132 public static function add_item_data( $data, $product_id ) {133 $result = self::posted_result( $product_id );191 public static function add_item_data( $data, $product_id, $variation_id = 0 ) { 192 $result = self::posted_result( $product_id, $variation_id ); 134 193 if ( null === $result || is_wp_error( $result ) ) { 135 194 return $data; … … 154 213 155 214 /** 215 * The stored measurement is authoritative: make the line quantity match it, 216 * so quantity and measurements can never disagree. 217 * 218 * @param array $item Cart item. 219 * @return array 220 */ 221 public static function lock_quantity( $item ) { 222 if ( empty( $item[ self::KEY ] ) || ! isset( $item[ self::KEY ]['packs'] ) ) { 223 return $item; 224 } 225 $settings = Cutpack_Settings::get_for( $item['product_id'], isset( $item['variation_id'] ) ? $item['variation_id'] : 0 ); 226 $item['quantity'] = Cutpack_Settings::MODE_PACKS === $settings['mode'] ? (int) $item[ self::KEY ]['packs'] : 1; 227 return $item; 228 } 229 230 /** 156 231 * Set the price of one cart unit (one pack, or one cut piece). 157 232 * … … 163 238 return $item; 164 239 } 165 $settings = Cutpack_Settings::get( $item['product_id'] ); 166 $price = Cutpack_Calculator::line_unit_price( $settings, $item[ self::KEY ], self::base_price( $item['product_id'] ) ); 240 $variation_id = isset( $item['variation_id'] ) ? (int) $item['variation_id'] : 0; 241 $settings = Cutpack_Settings::get_for( $item['product_id'], $variation_id ); 242 $price = Cutpack_Calculator::line_unit_price( $settings, $item[ self::KEY ], self::base_price( $variation_id ? $variation_id : $item['product_id'] ) ); 167 243 168 244 /** … … 285 361 return $item_data; 286 362 } 287 $settings = Cutpack_Settings::get ( $item['product_id']);363 $settings = Cutpack_Settings::get_for( $item['product_id'], isset( $item['variation_id'] ) ? $item['variation_id'] : 0 ); 288 364 foreach ( self::describe( $item[ self::KEY ], $settings, $item['quantity'] ) as $line ) { 289 365 $item_data[] = array( … … 307 383 return; 308 384 } 309 $settings = Cutpack_Settings::get ( $values['product_id']);385 $settings = Cutpack_Settings::get_for( $values['product_id'], isset( $values['variation_id'] ) ? $values['variation_id'] : 0 ); 310 386 foreach ( self::describe( $values[ self::KEY ], $settings, $values['quantity'] ) as $line ) { 311 387 $order_item->add_meta_data( $line[0], $line[1], true ); -
cut-and-pack-for-woocommerce/trunk/includes/class-cutpack-frontend.php
r3800171 r3805284 33 33 return $html; 34 34 } 35 $s = Cutpack_Settings::get( $product ); 35 $s = $product->is_type( 'variation' ) 36 ? Cutpack_Settings::get_for( $product->get_parent_id(), $product->get_id() ) 37 : Cutpack_Settings::get( $product ); 36 38 return $html . ' <span class="cutpack-per-unit">/ ' . esc_html( Cutpack_Settings::unit_label( $s['measure'] ) ) . '</span>'; 37 39 } … … 92 94 93 95 /** 96 * Per-variation data for the browser preview, keyed by variation ID. 97 * 98 * Built on the server so the preview never depends on theme markup or on 99 * WooCommerce's own variation scripts. 100 * 101 * @param WC_Product $product Variable product. 102 * @return array 103 */ 104 private static function variation_map( $product ) { 105 $map = array(); 106 if ( ! $product->is_type( 'variable' ) ) { 107 return $map; 108 } 109 110 /** 111 * Maximum number of variations sent to the browser preview. 112 * 113 * @param int $limit Limit. 114 */ 115 $limit = (int) apply_filters( 'cutpack_max_preview_variations', 500 ); 116 117 $children = array_slice( $product->get_children(), 0, $limit ); 118 if ( $children ) { 119 _prime_post_caches( $children, false, true ); 120 } 121 122 foreach ( $children as $variation_id ) { 123 $variation = wc_get_product( $variation_id ); 124 if ( ! $variation instanceof WC_Product_Variation || ! $variation->variation_is_visible() ) { 125 continue; 126 } 127 $vs = Cutpack_Settings::get_for( $product->get_id(), $variation->get_id() ); 128 $price = $variation->get_price(); 129 130 $map[ $variation->get_id() ] = array( 131 'coverage' => (float) $vs['coverage'], 132 'unitPrice' => '' === $price ? 0 : (float) wc_get_price_to_display( $variation ), 133 'purchasable' => '' !== $price && $variation->is_purchasable() && $variation->is_in_stock(), 134 'maxQty' => (int) $variation->get_max_purchase_quantity(), 135 ); 136 } 137 return $map; 138 } 139 140 /** 94 141 * Load the calculator script and its settings on enabled product pages. 95 142 */ … … 112 159 'cutpackData', 113 160 array( 114 'id' => 'cutpack-' . $product->get_id(), 115 'mode' => $s['mode'], 116 'measure' => $s['measure'], 117 'input' => $s['input'], 118 'coverage' => (float) $s['coverage'], 119 'min' => '' === $s['min'] ? 0 : (float) $s['min'], 120 'max' => '' === $s['max'] ? 0 : (float) $s['max'], 121 'step' => '' === $s['step'] ? 0 : (float) $s['step'], 122 'unitPrice' => (float) wc_get_price_to_display( $product ), 123 'unit' => Cutpack_Settings::unit_label( $s['measure'] ), 124 'currency' => array( 161 'id' => 'cutpack-' . $product->get_id(), 162 'mode' => $s['mode'], 163 'measure' => $s['measure'], 164 'input' => $s['input'], 165 'coverage' => (float) $s['coverage'], 166 'min' => '' === $s['min'] ? 0 : (float) $s['min'], 167 'max' => '' === $s['max'] ? 0 : (float) $s['max'], 168 'step' => '' === $s['step'] ? 0 : (float) $s['step'], 169 'unitPrice' => $product->is_type( 'variable' ) ? 0 : (float) wc_get_price_to_display( $product ), 170 'variable' => $product->is_type( 'variable' ), 171 'variations' => self::variation_map( $product ), 172 'unit' => Cutpack_Settings::unit_label( $s['measure'] ), 173 'currency' => array( 125 174 'symbol' => html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' ), 126 175 'format' => html_entity_decode( get_woocommerce_price_format(), ENT_QUOTES, 'UTF-8' ), … … 129 178 'thousands' => wc_get_price_thousand_separator(), 130 179 ), 131 'i18n' => array(180 'i18n' => array( 132 181 /* translators: 1: number of boxes, 2: amount, 3: unit, 4: price. Example: You need 17 boxes (24.48 m²) – £976.75 */ 133 'resultPacks' => __( 'You need %1$s (%2$s %3$s) – %4$s', 'cut-and-pack-for-woocommerce' ),182 'resultPacks' => __( 'You need %1$s (%2$s %3$s) – %4$s', 'cut-and-pack-for-woocommerce' ), 134 183 /* translators: 1: amount, 2: unit, 3: price. Example: 2.4 m – £43.20 */ 135 'resultCut' => __( '%1$s %2$s – %3$s', 'cut-and-pack-for-woocommerce' ),184 'resultCut' => __( '%1$s %2$s – %3$s', 'cut-and-pack-for-woocommerce' ), 136 185 /* translators: %s: a number */ 137 'oneBox' => __( '%s box', 'cut-and-pack-for-woocommerce' ),186 'oneBox' => __( '%s box', 'cut-and-pack-for-woocommerce' ), 138 187 /* translators: %s: a number */ 139 'manyBoxes' => __( '%s boxes', 'cut-and-pack-for-woocommerce' ), 140 'invalid' => __( 'Please enter a number greater than zero.', 'cut-and-pack-for-woocommerce' ), 141 'invalidSize' => __( 'Please enter a length and a width greater than zero.', 'cut-and-pack-for-woocommerce' ), 188 'manyBoxes' => __( '%s boxes', 'cut-and-pack-for-woocommerce' ), 189 'chooseOption' => __( 'Choose an option first.', 'cut-and-pack-for-woocommerce' ), 190 'unavailable' => __( 'This option is unavailable.', 'cut-and-pack-for-woocommerce' ), 191 /* translators: 1: number of boxes in stock, 2: amount covered, 3: unit such as m² */ 192 'stock' => __( 'Only %1$s in stock (%2$s %3$s).', 'cut-and-pack-for-woocommerce' ), 193 'invalid' => __( 'Please enter a number greater than zero.', 'cut-and-pack-for-woocommerce' ), 194 'invalidSize' => __( 'Please enter a length and a width greater than zero.', 'cut-and-pack-for-woocommerce' ), 142 195 /* translators: 1: minimum amount, 2: unit such as m² */ 143 'min' => __( 'The minimum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ),196 'min' => __( 'The minimum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ), 144 197 /* translators: 1: maximum amount, 2: unit such as m² */ 145 'max' => __( 'The maximum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ),198 'max' => __( 'The maximum is %1$s %2$s.', 'cut-and-pack-for-woocommerce' ), 146 199 ), 147 200 ) -
cut-and-pack-for-woocommerce/trunk/includes/class-cutpack-settings.php
r3800171 r3805284 66 66 */ 67 67 public static function get( $product ) { 68 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 68 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 69 70 /** 71 * Filter a product's Cut & Pack settings. 72 * 73 * @param array $settings Settings. 74 * @param WC_Product|null $product Product (the parent for a variation). 75 * @param WC_Product_Variation|null $variation Variation, when settings are read for one. 76 */ 77 return apply_filters( 'cutpack_product_settings', self::read( $product ), $product, null ); 78 } 79 80 /** 81 * Settings stored on a product, cleaned but not filtered. 82 * 83 * @param WC_Product|null $product Product. 84 * @return array 85 */ 86 private static function read( $product ) { 69 87 $settings = self::defaults(); 70 88 … … 78 96 } 79 97 80 /** 81 * Filter a product's Cut & Pack settings. 82 * 83 * @param array $settings Settings. 84 * @param WC_Product|null $product Product. 85 */ 86 return apply_filters( 'cutpack_product_settings', self::normalise( $settings ), $product ); 98 return self::normalise( $settings ); 99 } 100 101 /** 102 * Settings for a product, or for one of its variations. 103 * 104 * A variation may override the pack coverage; everything else comes from 105 * the parent product. A variation that does not belong to the product is ignored. 106 * 107 * @param int $product_id Parent (or simple) product ID. 108 * @param int $variation_id Variation ID, or 0. 109 * @return array 110 */ 111 public static function get_for( $product_id, $variation_id = 0 ) { 112 $product = wc_get_product( absint( $product_id ) ); 113 if ( ! $product instanceof WC_Product ) { 114 return self::get( null ); 115 } 116 117 $variation = self::owned_variation( $product, $variation_id ); 118 if ( ! $variation ) { 119 return self::get( $product ); 120 } 121 122 $settings = self::read( $product ); 123 $override = self::to_positive_decimal( $variation->get_meta( self::meta_key( 'coverage' ), true ) ); 124 if ( '' !== $override && self::MODE_PACKS === $settings['mode'] && self::MEASURE_AREA === $settings['measure'] ) { 125 $settings['coverage'] = $override; 126 } 127 128 /** This filter is documented in get(). */ 129 return apply_filters( 'cutpack_product_settings', self::normalise( $settings ), $product, $variation ); 130 } 131 132 /** 133 * The variation with this ID, but only if it really belongs to the product. 134 * 135 * @param WC_Product $product Parent product. 136 * @param int $variation_id Variation ID. 137 * @return WC_Product_Variation|null 138 */ 139 public static function owned_variation( $product, $variation_id ) { 140 $variation_id = absint( $variation_id ); 141 if ( ! $variation_id || ! $product instanceof WC_Product || ! $product->is_type( 'variable' ) ) { 142 return null; 143 } 144 $variation = wc_get_product( $variation_id ); 145 if ( $variation instanceof WC_Product && $variation->is_type( 'variation' ) && (int) $variation->get_parent_id() === (int) $product->get_id() ) { 146 return $variation; 147 } 148 return null; 87 149 } 88 150 … … 90 152 * Whether the calculator is switched on for a product. 91 153 * 92 * Version 1 supports simple products only. 154 * Works for simple and variable products. A variation counts as enabled 155 * when its parent is. 93 156 * 94 157 * @param WC_Product|int $product Product or product ID. … … 97 160 public static function is_enabled( $product ) { 98 161 $product = is_numeric( $product ) ? wc_get_product( $product ) : $product; 99 if ( ! $product instanceof WC_Product || ! $product->is_type( 'simple' ) ) { 162 if ( $product instanceof WC_Product && $product->is_type( 'variation' ) ) { 163 $product = wc_get_product( $product->get_parent_id() ); 164 } 165 if ( ! $product instanceof WC_Product || ! ( $product->is_type( 'simple' ) || $product->is_type( 'variable' ) ) ) { 100 166 return false; 101 167 } -
cut-and-pack-for-woocommerce/trunk/languages/cut-and-pack-for-woocommerce.pot
r3800171 r3805284 1 # Copyright (C) 2026 C ut & Pack1 # Copyright (C) 2026 Cartwright 2 2 # This file is distributed under the GPL-2.0-or-later. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Cut & Pack for WooCommerce 0.1.0\n"5 "Project-Id-Version: Cut & Pack for WooCommerce 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cut-and-pack-for-woocommerce\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 0-29T17:11:31+00:00\n"12 "POT-Creation-Date: 2026-11-13T09:29:09+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 27 27 #. Author of the plugin 28 28 #: cut-and-pack-for-woocommerce.php 29 #: includes/class-cutpack-admin.php:39 29 msgid "Cartwright" 30 msgstr "" 31 32 #. Author URI of the plugin 33 #: cut-and-pack-for-woocommerce.php 34 msgid "https://cartwrightplugins.com/" 35 msgstr "" 36 37 #: includes/class-cutpack-admin.php:41 30 38 msgid "Cut & Pack" 31 39 msgstr "" 32 40 33 #: includes/class-cutpack-admin.php:4 141 #: includes/class-cutpack-admin.php:43 34 42 msgid "Switch the calculator on for each product in its \"Made to measure\" tab." 35 43 msgstr "" 36 44 37 #: includes/class-cutpack-admin.php:4 545 #: includes/class-cutpack-admin.php:47 38 46 msgid "Remove data on uninstall" 39 47 msgstr "" 40 48 41 #: includes/class-cutpack-admin.php:4 649 #: includes/class-cutpack-admin.php:48 42 50 msgid "Delete all Cut & Pack product settings when the plugin is deleted. Measurements on past orders are always kept." 43 51 msgstr "" 44 52 45 #: includes/class-cutpack-admin.php:6 653 #: includes/class-cutpack-admin.php:68 46 54 msgid "Settings" 47 55 msgstr "" 48 56 49 #: includes/class-cutpack-admin.php: 7857 #: includes/class-cutpack-admin.php:80 50 58 msgid "Made to measure" 51 59 msgstr "" 52 60 53 #: includes/class-cutpack-admin.php:10 261 #: includes/class-cutpack-admin.php:104 54 62 msgid "Enable calculator" 55 63 msgstr "" 56 64 57 #: includes/class-cutpack-admin.php:10 365 #: includes/class-cutpack-admin.php:105 58 66 msgid "Shoppers enter a size instead of a quantity, and the price is calculated for them." 59 67 msgstr "" 60 68 61 #: includes/class-cutpack-admin.php:11 269 #: includes/class-cutpack-admin.php:114 62 70 msgid "Mode" 63 71 msgstr "" 64 72 65 #: includes/class-cutpack-admin.php:11 473 #: includes/class-cutpack-admin.php:116 66 74 msgid "Sold in packs (e.g. tiles, flooring)" 67 75 msgstr "" 68 76 69 #: includes/class-cutpack-admin.php:11 577 #: includes/class-cutpack-admin.php:117 70 78 msgid "Cut to size (e.g. fabric, blinds)" 71 79 msgstr "" 72 80 73 #: includes/class-cutpack-admin.php:1 1981 #: includes/class-cutpack-admin.php:121 74 82 msgid "Packs: the order is rounded up to whole boxes. Cut to size: the shopper pays for exactly the amount entered." 75 83 msgstr "" 76 84 77 #: includes/class-cutpack-admin.php:12 685 #: includes/class-cutpack-admin.php:128 78 86 msgid "Sold by" 79 87 msgstr "" 80 88 81 #: includes/class-cutpack-admin.php:1 2889 #: includes/class-cutpack-admin.php:130 82 90 msgid "Area (m²)" 83 91 msgstr "" 84 92 85 #: includes/class-cutpack-admin.php:1 2993 #: includes/class-cutpack-admin.php:131 86 94 msgid "Length (m)" 87 95 msgstr "" 88 96 89 #: includes/class-cutpack-admin.php:1 3897 #: includes/class-cutpack-admin.php:140 90 98 msgid "Shopper enters" 91 99 msgstr "" 92 100 93 #: includes/class-cutpack-admin.php:14 0101 #: includes/class-cutpack-admin.php:142 94 102 msgid "Total area" 95 103 msgstr "" 96 104 97 #: includes/class-cutpack-admin.php:14 1105 #: includes/class-cutpack-admin.php:143 98 106 msgid "Length × width" 99 107 msgstr "" 100 108 101 #: includes/class-cutpack-admin.php:149 109 #: includes/class-cutpack-admin.php:152 110 msgid "The price comes from each variation's own Regular price, read as a price per m² or per metre." 111 msgstr "" 112 113 #: includes/class-cutpack-admin.php:154 102 114 msgid "The price comes from the normal Regular price field on the General tab, read as a price per m² or per metre." 103 115 msgstr "" 104 116 105 117 #. translators: %s: unit, e.g. m² 106 #: includes/class-cutpack-admin.php:1 58118 #: includes/class-cutpack-admin.php:164 107 119 #, php-format 108 120 msgid "Coverage per pack (%s)" 109 121 msgstr "" 110 122 111 #: includes/class-cutpack-admin.php:16 3123 #: includes/class-cutpack-admin.php:169 112 124 msgid "How much one box covers. Stock is counted in boxes." 113 125 msgstr "" 114 126 115 127 #. translators: %s: unit, e.g. m² 116 #: includes/class-cutpack-admin.php:17 2128 #: includes/class-cutpack-admin.php:178 117 129 #, php-format 118 130 msgid "Minimum (%s)" 119 131 msgstr "" 120 132 121 #: includes/class-cutpack-admin.php:1 76133 #: includes/class-cutpack-admin.php:182 122 134 msgid "Smallest amount a shopper can order. Leave empty for no minimum." 123 135 msgstr "" 124 136 125 137 #. translators: %s: unit, e.g. m² 126 #: includes/class-cutpack-admin.php:1 84138 #: includes/class-cutpack-admin.php:190 127 139 #, php-format 128 140 msgid "Maximum (%s)" 129 141 msgstr "" 130 142 131 #: includes/class-cutpack-admin.php:1 88143 #: includes/class-cutpack-admin.php:194 132 144 msgid "Largest amount a shopper can order. Leave empty for no maximum." 133 145 msgstr "" 134 146 135 147 #. translators: %s: unit, e.g. m 136 #: includes/class-cutpack-admin.php: 196148 #: includes/class-cutpack-admin.php:202 137 149 #, php-format 138 150 msgid "Step (%s)" 139 151 msgstr "" 140 152 141 #: includes/class-cutpack-admin.php:20 1153 #: includes/class-cutpack-admin.php:207 142 154 msgid "Amounts are rounded up to this step, e.g. 0.1 turns 2.34 into 2.4." 143 155 msgstr "" 144 156 145 #: includes/class-cutpack-admin.php:2 09157 #: includes/class-cutpack-admin.php:215 146 158 msgid "Label text" 147 159 msgstr "" 148 160 149 #: includes/class-cutpack-admin.php:21 1150 #: includes/class-cutpack-frontend.php: 59161 #: includes/class-cutpack-admin.php:217 162 #: includes/class-cutpack-frontend.php:61 151 163 msgid "How many m² do you need?" 152 164 msgstr "" 153 165 154 #: includes/class-cutpack-admin.php:21 3166 #: includes/class-cutpack-admin.php:219 155 167 msgid "Optional wording shown above the calculator." 156 168 msgstr "" 157 169 158 #: includes/class-cutpack-admin.php:273 170 #. translators: %s: unit 171 #: includes/class-cutpack-admin.php:246 172 #, php-format 173 msgid "Pack size: coverage per pack (%s)" 174 msgstr "" 175 176 #: includes/class-cutpack-admin.php:248 177 msgid "Same as the product" 178 msgstr "" 179 180 #: includes/class-cutpack-admin.php:249 181 msgid "Only for packs. Leave empty to use the number from the \"Made to measure\" tab." 182 msgstr "" 183 184 #: includes/class-cutpack-admin.php:319 159 185 msgid "Enter how much one pack covers." 160 186 msgstr "" 161 187 162 #: includes/class-cutpack-admin.php: 277188 #: includes/class-cutpack-admin.php:323 163 189 msgid "The minimum is larger than the maximum." 164 190 msgstr "" 165 191 166 #: includes/class-cutpack-admin.php: 281192 #: includes/class-cutpack-admin.php:328 167 193 msgid "Enter a Regular price on the General tab (price per m² or per metre)." 168 194 msgstr "" 169 195 170 #: includes/class-cutpack-admin.php: 287196 #: includes/class-cutpack-admin.php:334 171 197 msgid "Cut & Pack: the calculator was switched off for this product." 172 198 msgstr "" 173 199 174 200 #: includes/class-cutpack-calculator.php:45 175 #: includes/class-cutpack-frontend.php:1 41201 #: includes/class-cutpack-frontend.php:194 176 202 msgid "Please enter a length and a width greater than zero." 177 203 msgstr "" … … 183 209 #. translators: 1: minimum amount, 2: unit such as m² 184 210 #: includes/class-cutpack-calculator.php:61 185 #: includes/class-cutpack-frontend.php:1 43211 #: includes/class-cutpack-frontend.php:196 186 212 #, php-format 187 213 msgid "The minimum is %1$s %2$s." … … 190 216 #. translators: 1: maximum amount, 2: unit such as m² 191 217 #: includes/class-cutpack-calculator.php:69 192 #: includes/class-cutpack-frontend.php:1 45218 #: includes/class-cutpack-frontend.php:198 193 219 #, php-format 194 220 msgid "The maximum is %1$s %2$s." … … 199 225 msgstr "" 200 226 227 #: includes/class-cutpack-cart.php:135 228 #: includes/class-cutpack-frontend.php:189 229 msgid "Choose an option first." 230 msgstr "" 231 201 232 #. translators: %s: product name 202 #: includes/class-cutpack-cart.php:2 06233 #: includes/class-cutpack-cart.php:282 203 234 #, php-format 204 235 msgid "%s was removed from your cart. Please enter the size you need on the product page and add it again." 205 236 msgstr "" 206 237 207 #: includes/class-cutpack-cart.php: 227238 #: includes/class-cutpack-cart.php:303 208 239 msgid "Coverage" 209 240 msgstr "" 210 241 211 242 #. translators: 1: amount, 2: unit, 3: number of boxes. Example: 24.48 m² (17 boxes) 212 #: includes/class-cutpack-cart.php: 230243 #: includes/class-cutpack-cart.php:306 213 244 #, php-format 214 245 msgid "%1$s %2$s (%3$s box)" … … 217 248 msgstr[1] "" 218 249 219 #: includes/class-cutpack-cart.php: 238220 #: includes/class-cutpack-cart.php: 246250 #: includes/class-cutpack-cart.php:314 251 #: includes/class-cutpack-cart.php:322 221 252 msgid "You entered" 222 253 msgstr "" 223 254 224 #: includes/class-cutpack-cart.php: 242255 #: includes/class-cutpack-cart.php:318 225 256 msgid "Length" 226 257 msgstr "" 227 258 228 #: includes/class-cutpack-cart.php: 242259 #: includes/class-cutpack-cart.php:318 229 260 msgid "Area" 230 261 msgstr "" 231 262 232 263 #. translators: abbreviation for metres 233 #: includes/class-cutpack-cart.php: 267234 #: includes/class-cutpack-settings.php: 171264 #: includes/class-cutpack-cart.php:343 265 #: includes/class-cutpack-settings.php:237 235 266 msgid "m" 236 267 msgstr "" 237 268 238 #: includes/class-cutpack-cart.php: 346269 #: includes/class-cutpack-cart.php:422 239 270 msgid "Enter size" 240 271 msgstr "" 241 272 242 #: includes/class-cutpack-frontend.php:5 5273 #: includes/class-cutpack-frontend.php:57 243 274 msgid "Enter the size of your area" 244 275 msgstr "" 245 276 246 #: includes/class-cutpack-frontend.php:5 7277 #: includes/class-cutpack-frontend.php:59 247 278 msgid "How many metres do you need?" 248 279 msgstr "" 249 280 250 281 #. translators: %s: unit 251 #: includes/class-cutpack-frontend.php:7 1282 #: includes/class-cutpack-frontend.php:73 252 283 #, php-format 253 284 msgid "Length (%s)" … … 255 286 256 287 #. translators: %s: unit 257 #: includes/class-cutpack-frontend.php:7 6288 #: includes/class-cutpack-frontend.php:78 258 289 #, php-format 259 290 msgid "Width (%s)" … … 261 292 262 293 #. translators: 1: number of boxes, 2: amount, 3: unit, 4: price. Example: You need 17 boxes (24.48 m²) – £976.75 263 #: includes/class-cutpack-frontend.php:1 33294 #: includes/class-cutpack-frontend.php:182 264 295 #, php-format 265 296 msgid "You need %1$s (%2$s %3$s) – %4$s" … … 267 298 268 299 #. translators: 1: amount, 2: unit, 3: price. Example: 2.4 m – £43.20 269 #: includes/class-cutpack-frontend.php:1 35300 #: includes/class-cutpack-frontend.php:184 270 301 #, php-format 271 302 msgid "%1$s %2$s – %3$s" … … 273 304 274 305 #. translators: %s: a number 275 #: includes/class-cutpack-frontend.php:1 37306 #: includes/class-cutpack-frontend.php:186 276 307 #, php-format 277 308 msgid "%s box" … … 279 310 280 311 #. translators: %s: a number 281 #: includes/class-cutpack-frontend.php:1 39312 #: includes/class-cutpack-frontend.php:188 282 313 #, php-format 283 314 msgid "%s boxes" 284 315 msgstr "" 285 316 286 #: includes/class-cutpack-frontend.php:140 317 #: includes/class-cutpack-frontend.php:190 318 msgid "This option is unavailable." 319 msgstr "" 320 321 #. translators: 1: number of boxes in stock, 2: amount covered, 3: unit such as m² 322 #: includes/class-cutpack-frontend.php:192 323 #, php-format 324 msgid "Only %1$s in stock (%2$s %3$s)." 325 msgstr "" 326 327 #: includes/class-cutpack-frontend.php:193 287 328 msgid "Please enter a number greater than zero." 288 329 msgstr "" 289 330 290 331 #. translators: abbreviation for square metres 291 #: includes/class-cutpack-settings.php: 173332 #: includes/class-cutpack-settings.php:239 292 333 msgid "m²" 293 334 msgstr "" -
cut-and-pack-for-woocommerce/trunk/readme.txt
r3800171 r3805284 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 47 47 1. Install and activate WooCommerce. 48 48 2. Go to Plugins → Add New, search for "Cut & Pack", then install and activate it. 49 3. Edit a simple product. On the General tab, enter the price per m² (or per metre) as the Regular price.49 3. Edit a simple or variable product and enter the price per m² (or per metre) as the Regular price (on a variable product, on each variation). 50 50 4. Open the new "Made to measure" tab, tick "Enable calculator" and choose the mode. 51 51 5. For packs, enter how much one box covers (for example 1.44 m²). … … 56 56 = Which product types are supported? = 57 57 58 Simple products. Support for variable products (for example one floor in several finishes) is planned. 58 Simple and variable products. On a variable product (for example one floor in several finishes) each variation has its own price per m², its own stock and, if you like, its own pack size. Grouped and external products are not supported. 59 60 = Can each variation have a different pack size? = 61 62 Yes. Switch the calculator on in the product's "Made to measure" tab and enter the usual pack size. In each variation's panel you can enter a different "Pack size"; leave it empty to use the product's. Stock is counted in boxes, so if a finish has 5 boxes left the shopper is told so instead of being able to order more. 63 64 = What does "Order again" do with measured items? = 65 66 Measured items are not added again automatically, because the size has to be entered again. The shopper opens the product page and enters the size. 59 67 60 68 = What price do I enter? = … … 94 102 == Changelog == 95 103 104 = 1.1.0 = 105 * New: variable products. Each variation can have its own price per m² (or per metre), its own stock and, optionally, its own pack size. 106 * New: a finish that has only a few boxes left tells the shopper how many boxes can be ordered. 107 * Developers: the `cutpack_product_settings` filter now receives the parent product as its second argument and, for a variation, the variation as a third argument. 108 96 109 = 1.0.0 = 97 110 * First release. … … 99 112 == Upgrade Notice == 100 113 114 = 1.1.0 = 115 Adds support for variable products (different price, stock and pack size per variation). 116 101 117 = 1.0.0 = 102 118 First release.
Note:
See TracChangeset
for help on using the changeset viewer.