Changeset 3343431
- Timestamp:
- 08/12/2025 10:06:56 AM (6 months ago)
- Location:
- garantie-sgr/trunk
- Files:
-
- 2 edited
-
garantie-sgr.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
garantie-sgr/trunk/garantie-sgr.php
r3343406 r3343431 4 4 * Plugin URL: https://uprise.ro 5 5 * Description: Extensie WooCommerce pentru sistemul garanție-returnare SGR. 6 * Version: 2.0. 16 * Version: 2.0.2 7 7 * Author: Eduard V. Doloc 8 8 * Author URI: https://uprise.ro … … 12 12 * WC requires at least: 7.9 13 13 * WC tested up to: 10.0 14 * Stable tag: 2.0. 114 * Stable tag: 2.0.2 15 15 * Requires Plugins: woocommerce 16 16 * License: GPLv2 or later … … 22 22 23 23 if ( ! defined( 'GARANTIE_SGR_VERSION' ) ) { 24 define( 'GARANTIE_SGR_VERSION', '2.0. 1' );24 define( 'GARANTIE_SGR_VERSION', '2.0.2' ); 25 25 } 26 26 … … 103 103 104 104 // create the product if it's missing 105 function garantie_svg_product_create() { 106 if ( ! class_exists( 'WC_Product_Simple' ) ) { 107 return false; 108 } 109 // safeguard for older wc 110 if ( ! function_exists( 'wc_get_product_id_by_sku' ) ) { 111 return false; 112 } 113 114 $sgr_sku = 'TAXA-SGR'; 115 $product_id = wc_get_product_id_by_sku( $sgr_sku ); 116 117 if ( $product_id ) { 118 update_option( 'garantie_sgr_product_id', (int) $product_id ); 119 120 return (int) $product_id; 121 } 122 123 $product = new WC_Product_Simple(); 124 $product->set_name( __( 'Taxă SGR', 'garantie-sgr' ) ); 125 $product->set_sku( $sgr_sku ); 126 $product->set_regular_price( '0.50' ); 127 $product->set_price( '0.50' ); 128 $product->set_tax_status( 'none' ); 129 $product->set_description( __( 'Taxă garanție SGR', 'garantie-sgr' ) ); 130 $product->set_catalog_visibility( 'hidden' ); 131 $product->set_status( 'publish' ); 132 $product->set_virtual( true ); 133 134 $product_id = $product->save(); 135 if ( $product_id && ! is_wp_error( $product_id ) ) { 136 // Backdate to Unix epoch start. 137 wp_update_post( array( 138 'ID' => $product_id, 139 'post_date' => '1970-01-01 00:00:00', 140 'post_date_gmt' => '1970-01-01 00:00:00', 141 ) ); 142 update_option( 'garantie_sgr_product_id', (int) $product_id ); 143 144 $attach_id = sgr_image_check( 'produs-sgr.gif' ); 105 function garantie_sgr_product_create() { 106 if ( ! function_exists( 'wp_insert_post' ) ) { 107 return false; 108 } 109 110 $sgr_sku = 'TAXA-SGR'; 111 112 if ( function_exists( 'wc_get_product_id_by_sku' ) ) { 113 $existing_id = wc_get_product_id_by_sku( $sgr_sku ); 114 if ( $existing_id ) { 115 update_option( 'garantie_sgr_product_id', (int) $existing_id ); 116 117 return (int) $existing_id; 118 } 119 } 120 121 $postarr = array( 122 'post_title' => __( 'Taxă SGR', 'garantie-sgr' ), 123 'post_type' => 'product', 124 'post_status' => 'publish', 125 // Ensure product type exists *during* save_post so wc_get_product() works 126 'tax_input' => array( 127 'product_type' => array( 'simple' ), 128 ), 129 ); 130 131 $product_id = wp_insert_post( $postarr, true ); 132 if ( is_wp_error( $product_id ) || ! $product_id ) { 133 return false; 134 } 135 136 // Core Woo metas (no HTML, so sanitize_text_field is fine for scalar metas) 137 update_post_meta( $product_id, '_sku', $sgr_sku ); 138 update_post_meta( $product_id, '_price', '0.50' ); 139 update_post_meta( $product_id, '_regular_price', '0.50' ); 140 update_post_meta( $product_id, '_tax_status', 'none' ); 141 update_post_meta( $product_id, '_virtual', 'yes' ); 142 update_post_meta( $product_id, '_manage_stock', 'no' ); 143 144 // Hide from catalog (product_visibility term) 145 if ( taxonomy_exists( 'product_visibility' ) ) { 146 // Don’t touch other terms, just add exclude-from-catalog 147 wp_set_object_terms( $product_id, 'exclude-from-catalog', 'product_visibility', true ); 148 } 149 150 // Backdate to Unix epoch start (creation-only) 151 wp_update_post( array( 152 'ID' => $product_id, 153 'post_date' => '1970-01-01 00:00:00', 154 'post_date_gmt' => '1970-01-01 00:00:00', 155 ) ); 156 157 // Thumbnail from bundled image (reuse if exists) 158 if ( function_exists( 'set_post_thumbnail' ) ) { 159 $attach_id = function_exists( 'sgr_image_check' ) ? sgr_image_check( 'produs-sgr.jpg' ) : false; 145 160 if ( $attach_id ) { 146 set_post_thumbnail( $product_id, $attach_id );147 } 148 149 return (int) $product_id; 150 }151 152 return false;161 set_post_thumbnail( $product_id, (int) $attach_id ); 162 } 163 } 164 165 update_option( 'garantie_sgr_product_id', (int) $product_id ); 166 167 return (int) $product_id; 153 168 } 154 169 … … 185 200 186 201 if ( $needs ) { 187 garantie_s vg_product_create();202 garantie_sgr_product_create(); 188 203 update_option( 'garantie_sgr_version', GARANTIE_SGR_VERSION ); 189 204 delete_option( 'garantie_sgr_pending_setup' ); -
garantie-sgr/trunk/readme.txt
r3343423 r3343431 8 8 WC requires at least: 7.9 9 9 WC tested up to: 10.0 10 Stable tag: 2.0. 110 Stable tag: 2.0.2 11 11 Requires Plugins: woocommerce 12 12 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.