forked from dkjensen/wc-cart-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwc-cart-pdf-compatibility.php
134 lines (117 loc) · 3.46 KB
/
wc-cart-pdf-compatibility.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Plugin and language compatibility
*
* @package dkjensen/wc-cart-pdf
*/
/**
* TM Extra Product Options
*
* @see https://codecanyon.net/item/woocommerce-extra-product-options/7908619
* @return void
*/
function wc_cart_pdf_compatibility_tm_extra_product_options() {
add_filter( 'wc_epo_no_edit_options', '__return_true' ); // Hide "Edit options" link on product title.
}
add_action( 'wc_cart_pdf_before_process', 'wc_cart_pdf_compatibility_tm_extra_product_options' );
/**
* Gravity PDF
*
* @return void
*/
function wc_cart_pdf_compatibility_gravity_pdf() {
// phpcs:ignore
if ( class_exists( 'GFPDF_Major_Compatibility_Checks' ) && isset( $GLOBALS['gravitypdf'] ) && isset( $_GET['cart-pdf'] ) ) {
remove_action( 'plugins_loaded', array( $GLOBALS['gravitypdf'], 'plugins_loaded' ) );
}
}
add_action( 'plugins_loaded', 'wc_cart_pdf_compatibility_gravity_pdf', 0 );
/**
* Visual Products Configurator
*
* @return void
*/
function wc_cart_pdf_compatibility_visual_products_configurator() {
add_filter(
'vpc_get_config_data',
function( $thumbnail_code ) {
$edit_i18n = __( 'Edit', 'wc-cart-pdf' );
$thumbnail_code = preg_replace( '/<\s*a[^>]*>' . $edit_i18n . '<\s*\/\s*a>/', '', $thumbnail_code ); // Hide the "Edit" link.
return $thumbnail_code;
}
);
}
add_action( 'wc_cart_pdf_before_process', 'wc_cart_pdf_compatibility_visual_products_configurator' );
/**
* Try removing product thumbnails filters if not rendering properly
*
* @return void
*/
function child_wc_cart_pdf_remove_thumbnail_filters() {
if ( defined( 'WC_CART_PDF_THUMBNAIL_COMPATIBILITY' ) && constant( 'WC_CART_PDF_THUMBNAIL_COMPATIBILITY' ) ) {
remove_all_filters( 'wp_get_attachment_image_src' );
remove_all_filters( 'wp_get_attachment_image' );
remove_all_filters( 'woocommerce_cart_item_thumbnail' );
remove_all_filters( 'woocommerce_product_get_image' );
}
}
add_action( 'wc_cart_pdf_before_process', 'child_wc_cart_pdf_remove_thumbnail_filters' );
/**
* Multilingual support
*
* @param array $args MPDF args.
* @return array
*/
function wc_cart_pdf_compatibility_language( $args ) {
$site_lang = get_locale();
switch ( $site_lang ) {
case 'zh_CN': // Chinese (simplified).
case 'zh_TW': // Chinese (traditional).
$defaultConfig = ( new Mpdf\Config\ConfigVariables() )->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = ( new Mpdf\Config\FontVariables() )->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$args['fontDir'] = array_merge(
$fontDirs,
array(
WC_CART_PDF_PATH . 'resources/fonts',
)
);
$args['fontdata'] = $fontData + array(
'yahei' => array(
'R' => 'yahei.ttf',
),
);
$args['default_font'] = 'yahei';
$args['mode'] = '+aCJK';
break;
case 'ja': // Japanese.
case 'ur': // Urdu.
case 'am': // Amharic.
case 'gu': // Gujarati.
case 'hi_IN': // Hindi.
case 'kn': // Kannada.
case 'km': // Khmer.
case 'ko_KR': // Korean.
case 'ml_IN': // Malayalam.
case 'mr': // Marathi.
case 'my_MM': // Myanmar (burmese).
case 'ne_NP': // Nepali.
case 'pa_IN': // Punjabi.
case 'si_LK': // Sinhala.
case 'ta_IN': // Tamil.
case 'te': // Telugu.
case 'th': // Thai.
add_filter(
'wc_cart_pdf_mpdf',
function( $mpdf ) {
$mpdf->autoScriptToLang = true;
return $mpdf;
}
);
$args['mode'] = '+aCJK';
break;
}
return $args;
}
add_filter( 'wc_cart_pdf_mpdf_args', 'wc_cart_pdf_compatibility_language' );