/var/www/html_us/wp-content/plugins/dream-team/plugins/custom.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
 * Stripe Payment Plugin for WooCommerce
 * https://wordpress.org/plugins/payment-gateway-stripe-and-woocommerce-integration/
 */
add_filter('eh_stripe_payment_intent_args''kd_stripe_payment_intent_args'999);
function 
kd_stripe_payment_intent_args($charge) {
    
$order_id absintWC()->session->get'order_awaiting_payment' ) );
    
$order $order_id wc_get_order$order_id ) : null;

    
$settings get_option('woocommerce_eh_stripe_pay_settings');
    
$referer = !empty($settings['dreamteam_stripe_domain'])? $settings['dreamteam_stripe_domain'] : false;
    
$shop_name = !empty($settings['dreamteam_stripe_store'])? $settings['dreamteam_stripe_store'] : false;

    unset(
$charge['metadata']['Products']);
    unset(
$charge['metadata']['Total Tax']);
    
// unset($charge['metadata']['Referer']);
    
if ($referer) {
        
$charge['metadata']['Referer'] = $referer;
    } else {
        unset(
$charge['metadata']['Referer']);
    }

    
// description
    
$order_number = ($order && !empty($order))? $order->get_order_number() : $order_id;
    if (!empty(
$shop_name) && !empty($order_number)) {
        
$charge['description'] = $shop_name ' Order#' $order_number;
    }

    return 
$charge;
}

function 
dreamteam_array_insert_after( array $array$key, array $new ) {
    
$keys array_keys$array );
    
$index array_search$key$keys );
    
$pos false === $index count$array ) : $index 1;

    return 
array_mergearray_slice$array0$pos ), $newarray_slice$array$pos ) );
}

add_filter('pmw_output_product_prices_with_tax''__return_false'99);

add_filter('woocommerce_settings_api_form_fields_eh_stripe_pay''dreamteam_custom_eh_stripe_settings'9991);

function 
dreamteam_custom_eh_stripe_settings($fiels) {
    
$doamin = array(
        
'dreamteam_stripe_domain' => array(
            
'title'       => __'Referer custom''dreamteam' ),
            
'type'        => 'text',
            
'description' => __'Set domain for stripe: ''dreamteam' ),
            
'default'     => '',
            
'desc_tip'    => true,
        ),
        
'dreamteam_stripe_store' => array(
            
'title'       => __'Custom Shop Name''dreamteam' ),
            
'type'        => 'text',
            
'description' => __'Set Shop name for stripe: ''dreamteam' ),
            
'default'     => '',
            
'desc_tip'    => true,
        )
    );

    return 
dreamteam_array_insert_after($fiels'eh_stripe_capture'$doamin);
}

function 
dreamteam_add_inline_script_with_product_meta() {
    if (
is_product()) {
        global 
$post// Lấy thông tin bài viết hiện tại (sản phẩm)
        
$product_id $post->ID;
    
        
// Lấy giá trị meta data với key "custom_meta_key"
        
$meta_value get_post_meta($product_id'dreamteam_limit_sizes'true);
        
$meta_value wp_json_encode($meta_value);
    
        
// Kiểm tra nếu meta value không rỗng
        
if (!empty($meta_value)) {
            
// Tạo script inline
            
$custom_script "
                const DRT_PRODUCT_LIMIT_SIZE = 
$meta_value;
            "
;
            
// Thêm script inline sau khi jQuery được enqueue
            
wp_add_inline_script('jquery'$custom_script);
    
            
wp_enqueue_script(
                
'drt-variation-custom-product-js'// Handle của script
                
DREAMTEAM_CORE_PLUGIN_URL 'assets/js/product-custom.js',
                array(
'jquery'), // Các script phụ thuộc (nếu có)
                
time(), // Phiên bản
                
true // Đặt true để load ở footer
            
);
        }
    }
}
add_action('wp_enqueue_scripts''dreamteam_add_inline_script_with_product_meta');