تابع wc_update_240_refunds بروزرسانی استرداد ووکامرس به نسخه 2.4.0

تابع wc_update_240_refunds بروزرسانی استرداد ووکامرس به نسخه 2.4.0

تابع ووکامرسی wc_update_240_refunds – بروزرسانی گزینه های استرداد ووکامرس به نسخه 2.4.0

Syntax – سینتکس

wc_update_240_refunds(); 

Usage – نحوه استفاده

if ( !function_exists( 'wc_update_240_refunds' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-update-functions.php'; 
} 
 
  
// NOTICE! Understand what this does before running. 
$result = wc_update_240_refunds(); 
    

Defined – محل تعریف

/includes/wc-update-functions.php

function wc_update_240_refunds() { 
    global $wpdb; 
    /** 
     * Refunds for full refunded orders. 
     * Update fully refunded orders to ensure they have a refund line item so reports add up. 
     */ 
    $refunded_orders = get_posts( array( 
        'posts_per_page' => -1,  
        'post_type' => 'shop_order',  
        'post_status' => array( 'wc-refunded' ),  
 ) ); 
 
    // Ensure emails are disabled during this update routine 
    remove_all_actions( 'woocommerce_order_status_refunded_notification' ); 
    remove_all_actions( 'woocommerce_order_partially_refunded_notification' ); 
    remove_action( 'woocommerce_order_status_refunded', array( 'WC_Emails', 'send_transactional_email' ) ); 
    remove_action( 'woocommerce_order_partially_refunded', array( 'WC_Emails', 'send_transactional_email' ) ); 
 
    foreach ( $refunded_orders as $refunded_order ) { 
        $order_total = get_post_meta( $refunded_order->ID, '_order_total', true ); 
        $refunded_total = $wpdb->get_var( $wpdb->prepare( " 
            SELECT SUM( postmeta.meta_value ) 
            FROM $wpdb->postmeta AS postmeta 
            INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d ) 
            WHERE postmeta.meta_key = '_refund_amount' 
            AND postmeta.post_id = posts.ID 
        ", $refunded_order->ID ) ); 
 
        if ( $order_total > $refunded_total ) { 
            wc_create_refund( array( 
                'amount' => $order_total - $refunded_total,  
                'reason' => __( 'Order fully refunded', woocommerce ),  
                'order_id' => $refunded_order->ID,  
                'line_items' => array(),  
                'date' => $refunded_order->post_modified,  
 ) ); 
        } 
    } 
 
    wc_delete_shop_order_transients(); 
} 

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us