Plugin Directory

Changeset 3451026


Ignore:
Timestamp:
01/31/2026 02:33:08 PM (3 weeks ago)
Author:
facturaone
Message:

v4.77

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-facturaone/trunk/wp-facturaone.php

    r3450909 r3451026  
    44Plugin URI: https://www.facturaone.com/
    55Description: La forma más fácil de trabajar con tu tienda online desde nuestro ERP FacturaONE.
    6 Version: 4.76
     6Version: 4.77
    77Author: FacturaONE
    88Author URI: https://www.facturaone.com/
     
    4040    add_action('admin_init', 'FONE_get_version');
    4141}
     42
     43
     44
     45//// Cron cada minuto (FacturaONE watchdog)
     46//add_filter('cron_schedules', function($schedules){
     47//    if (!isset($schedules['fone_1min'])) {
     48//        $schedules['fone_1min'] = array(
     49//            'interval' => 60,
     50//            'display'  => 'FacturaONE every minute'
     51//        );
     52//    }
     53//    return $schedules;
     54//});
     55//add_action('init', function(){
     56//    // Solo si está activo el módulo WordPress
     57//    $mod_wordpress = (int) get_option('mod_wordpress');
     58//    if ($mod_wordpress <= 0) return;
     59//
     60//    if (!wp_next_scheduled('fone_jobs_tick')) {
     61//        wp_schedule_event(time() + 60, 'fone_1min', 'fone_jobs_tick');
     62//    }
     63//});
     64//
     65//add_action('fone_jobs_tick', function(){
     66//    $mod_wordpress = (int) get_option('mod_wordpress');
     67//    if ($mod_wordpress <= 0) return;
     68//
     69//    $job_id = (int) get_option('_facturaone_status_backgroundid', 0);
     70//    if ($job_id <= 0) return;
     71//
     72//    global $wpdb;
     73//    $table = $wpdb->prefix . 'fone_jobs';
     74//
     75//    $pend = (int) $wpdb->get_var($wpdb->prepare(
     76//        "SELECT COUNT(*) FROM $table WHERE job_id=%d AND status IN (0,1)",
     77//        $job_id
     78//    ));
     79//    if ($pend <= 0) return;
     80//
     81//    $last = (int) get_option('_facturaone_job_last_run_' . $job_id, 0);
     82//    if ($last && (time() - $last) < 60) return;
     83//
     84//    update_option('_facturaone_job_last_run_' . $job_id, time());
     85//
     86//    if (function_exists('FONE_execajax')) {
     87//        FONE_execajax('update_stock', $job_id);
     88//    }
     89//});
     90
     91
    4292
    4393//variables genereales
     
    610660        }
    611661
    612         if ($deletevariaciones === true && trim((string)$variaciones) !== '') {
     662        if ($deletevariaciones === true) {
    613663            FONE_delete_product_image_variaciones($_product_id);
    614664        }
     
    15711621        $_product_id = fone_get_product_id_by_idfactura($item_lookup_id);
    15721622        if ($_product_id>0 && $sobreescribe==true){
    1573             //elimina siempre variaciones anteriores
    1574             //FONE_delete_product_image_variaciones($_product_id);
    15751623            FONE_delete_product_images($_product_id, $borragaleriaimag);
    15761624        }
     
    30023050function FONE_delete_product_image_variaciones( $post_id )
    30033051{
    3004     $product = wc_get_product( $post_id );
    3005     if ( !$product ) {
    3006         return;
    3007     }
    3008     if( $product->is_type( 'variable' ) ){
    3009         $variations = $product->get_available_variations();
    3010         if( !empty( $variations ) ) {
    3011             foreach( $variations as $variation ) {
    3012                 $image_id = $variation['image_id'];
    3013                 if ($image_id>0){
    3014                     wp_delete_post( $image_id );
    3015                 }
    3016             }
    3017         }
    3018     }
     3052    $product = wc_get_product( $post_id );
     3053    if ( !$product || !$product->is_type('variable') ) return;
     3054
     3055    // borrar variaciones + imágenes
     3056    foreach ( $product->get_children() as $variation_id ) {
     3057        if ( $img_id = get_post_thumbnail_id( $variation_id ) ) {
     3058            wp_delete_post( $img_id, true );
     3059        }
     3060        wp_delete_post( $variation_id, true );
     3061    }
     3062
     3063    // recargar producto ya sin variaciones
     3064    $product = wc_get_product( $post_id );
     3065
     3066    // convertir a simple
     3067    wp_set_object_terms( $post_id, 'simple', 'product_type', false );
     3068
     3069    $product->set_attributes( [] );
     3070    $product->set_default_attributes( [] );
     3071
     3072    delete_post_meta( $post_id, '_product_attributes' );
     3073    delete_post_meta( $post_id, '_default_attributes' );
     3074
     3075    $product->save();
    30193076}
    30203077function FONE_wh_deleteProduct($id, $force = FALSE)
Note: See TracChangeset for help on using the changeset viewer.