質問編集履歴
4
コードの余計な記号を消去
test
CHANGED
File without changes
|
test
CHANGED
@@ -252,7 +252,7 @@
|
|
252
252
|
|
253
253
|
'price' => $product->get_price(),
|
254
254
|
|
255
|
-
'dollPrice' =>intval($product->get_price()) / 1.2
|
255
|
+
'dollPrice' =>intval($product->get_price()) / 1.2,
|
256
256
|
|
257
257
|
)
|
258
258
|
|
3
質問内容の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,53 +1,307 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
wo
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
i
|
10
|
-
|
11
|
-
|
1
|
+
### 前提・実現したいこと
|
2
|
+
|
3
|
+
$product->get_dollPrice_html()の値を1.2で割りたい。そこでwc_get_price_to_displayの連想配列に'price'を1.2で割った'dollPrice' => $dollPriceを追加して解決しようと試みた。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
### 発生している問題・エラーメッセージ
|
8
|
+
|
9
|
+
自分で作った$product->get_dollPrice_html()(詳細は該当のコードエリアにて)で出力した結果が、既存の$product->get_price_html()で出力した結果と変わらない。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
### 試したこと
|
16
|
+
|
17
|
+
get_price_html()を見てみると以下の記述があった。
|
18
|
+
|
19
|
+
```php
|
20
|
+
|
21
|
+
public function get_price_html( $deprecated = '' ) {
|
22
|
+
|
23
|
+
if ( '' === $this->get_price() ) {
|
24
|
+
|
25
|
+
$price = apply_filters( 'woocommerce_empty_price_html', '', $this );
|
26
|
+
|
27
|
+
} elseif ( $this->is_on_sale() ) {
|
28
|
+
|
29
|
+
$price = wc_format_sale_price( wc_get_price_to_display( $this, array( 'price' => $this->get_regular_price() ) ), wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
30
|
+
|
31
|
+
} else {
|
32
|
+
|
33
|
+
$price = wc_price( wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
return apply_filters( 'woocommerce_get_price_html', $price, $this );
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
自分の状況はelseの場合のみしかないのでwc_price()とwc_get_price_to_display()のみを考え、それらの内容は以下の通りだった。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```php
|
50
|
+
|
51
|
+
function wc_price( $price, $args = array() ) {
|
52
|
+
|
53
|
+
$args = apply_filters(
|
54
|
+
|
55
|
+
'wc_price_args',
|
56
|
+
|
57
|
+
wp_parse_args(
|
58
|
+
|
59
|
+
$args,
|
60
|
+
|
61
|
+
array(
|
62
|
+
|
63
|
+
'ex_tax_label' => false,
|
64
|
+
|
65
|
+
'currency' => '',
|
66
|
+
|
67
|
+
'decimal_separator' => wc_get_price_decimal_separator(),
|
68
|
+
|
69
|
+
'thousand_separator' => wc_get_price_thousand_separator(),
|
70
|
+
|
71
|
+
'decimals' => wc_get_price_decimals(),
|
72
|
+
|
73
|
+
'price_format' => get_woocommerce_price_format(),
|
74
|
+
|
75
|
+
)
|
76
|
+
|
77
|
+
)
|
78
|
+
|
79
|
+
);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
$unformatted_price = $price;
|
84
|
+
|
85
|
+
$negative = $price < 0;
|
86
|
+
|
87
|
+
$price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );
|
88
|
+
|
89
|
+
$price = apply_filters( 'formatted_woocommerce_price', number_format( $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'] ), $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'] );
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $args['decimals'] > 0 ) {
|
94
|
+
|
95
|
+
$price = wc_trim_zeros( $price );
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
$formatted_price = ( $negative ? '-' : '' ) . sprintf( $args['price_format'], '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $args['currency'] ) . '</span>', $price );
|
102
|
+
|
103
|
+
$return = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if ( $args['ex_tax_label'] && wc_tax_enabled() ) {
|
108
|
+
|
109
|
+
$return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
/**
|
118
|
+
|
119
|
+
* Filters the string of price markup.
|
120
|
+
|
121
|
+
*
|
122
|
+
|
123
|
+
* @param string $return Price HTML markup.
|
124
|
+
|
125
|
+
* @param string $price Formatted price.
|
126
|
+
|
127
|
+
* @param array $args Pass on the args.
|
128
|
+
|
129
|
+
* @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0.
|
130
|
+
|
131
|
+
*/
|
132
|
+
|
133
|
+
return apply_filters( 'wc_price', $return, $price, $args, $unformatted_price );
|
12
134
|
|
13
135
|
}
|
14
136
|
|
15
|
-
|
137
|
+
```
|
138
|
+
|
16
|
-
|
139
|
+
```php
|
140
|
+
|
141
|
+
function wc_get_price_to_display( $product, $args = array() ) {
|
142
|
+
|
143
|
+
$args = wp_parse_args(
|
144
|
+
|
145
|
+
$args,
|
146
|
+
|
147
|
+
array(
|
148
|
+
|
149
|
+
'qty' => 1,
|
150
|
+
|
151
|
+
'price' => $product->get_price(),
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
)
|
156
|
+
|
157
|
+
);
|
158
|
+
|
159
|
+
$price = $args['price'];
|
160
|
+
|
161
|
+
$qty = $args['qty'];
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
|
166
|
+
|
167
|
+
wc_get_price_including_tax(
|
168
|
+
|
17
|
-
|
169
|
+
$product,
|
18
|
-
|
19
|
-
|
20
|
-
|
170
|
+
|
21
|
-
|
171
|
+
array(
|
172
|
+
|
22
|
-
|
173
|
+
'qty' => $qty,
|
174
|
+
|
23
|
-
|
175
|
+
'price' => $price,
|
176
|
+
|
177
|
+
|
178
|
+
|
24
|
-
|
179
|
+
)
|
180
|
+
|
181
|
+
) :
|
182
|
+
|
25
|
-
|
183
|
+
wc_get_price_excluding_tax(
|
184
|
+
|
26
|
-
|
185
|
+
$product,
|
186
|
+
|
187
|
+
array(
|
188
|
+
|
27
|
-
|
189
|
+
'qty' => $qty,
|
28
|
-
|
190
|
+
|
29
|
-
|
191
|
+
'price' => $price,
|
192
|
+
|
193
|
+
|
194
|
+
|
30
|
-
|
195
|
+
)
|
196
|
+
|
31
|
-
|
197
|
+
);
|
32
198
|
|
33
199
|
}
|
34
200
|
|
35
201
|
|
36
202
|
|
37
|
-
?>
|
38
|
-
|
39
|
-
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
|
40
|
-
|
41
|
-
<?php
|
42
|
-
|
43
|
-
echo $product->get_price_html();?><br>
|
44
|
-
|
45
|
-
<?php
|
46
|
-
|
47
|
-
echo get($product->get_price_html()); ?></p>
|
48
|
-
|
49
|
-
```
|
203
|
+
```
|
204
|
+
|
205
|
+
|
206
|
+
|
50
|
-
|
207
|
+
### 該当のソースコード
|
208
|
+
|
51
|
-
|
209
|
+
新たに自分で作ったget_dollPrice_html()のコード
|
210
|
+
|
52
|
-
|
211
|
+
```php
|
212
|
+
|
213
|
+
public function get_dollPrice_html( $deprecated = '' ) {
|
214
|
+
|
215
|
+
if ( '' === $this->get_price() ) {
|
216
|
+
|
53
|
-
|
217
|
+
$dollPrice = apply_filters( 'woocommerce_empty_price_html', '', $this );
|
218
|
+
|
219
|
+
} elseif ( $this->is_on_sale() ) {
|
220
|
+
|
221
|
+
$dollPprice = wc_format_sale_price( wc_get_price_to_display( $this, array( 'price' => $this->get_regular_price() ) ), wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
222
|
+
|
223
|
+
} else {
|
224
|
+
|
225
|
+
$dollPrice = wc_price( wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
return apply_filters( 'woocommerce_get_price_html', $dollPrice, $this );
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
改変したwc_get_price_to_display()
|
240
|
+
|
241
|
+
```php
|
242
|
+
|
243
|
+
function wc_get_price_to_display( $product, $args = array() ) {
|
244
|
+
|
245
|
+
$args = wp_parse_args(
|
246
|
+
|
247
|
+
$args,
|
248
|
+
|
249
|
+
array(
|
250
|
+
|
251
|
+
'qty' => 1,
|
252
|
+
|
253
|
+
'price' => $product->get_price(),
|
254
|
+
|
255
|
+
'dollPrice' =>intval($product->get_price()) / 1.2;
|
256
|
+
|
257
|
+
)
|
258
|
+
|
259
|
+
);
|
260
|
+
|
261
|
+
$price = $args['price'];
|
262
|
+
|
263
|
+
$qty = $args['qty'];
|
264
|
+
|
265
|
+
$dollPrice = $arg['dollPrice'];
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
|
270
|
+
|
271
|
+
wc_get_price_including_tax(
|
272
|
+
|
273
|
+
$product,
|
274
|
+
|
275
|
+
array(
|
276
|
+
|
277
|
+
'qty' => $qty,
|
278
|
+
|
279
|
+
'price' => $price,
|
280
|
+
|
281
|
+
'dollPrice' => $dollPrice,
|
282
|
+
|
283
|
+
)
|
284
|
+
|
285
|
+
) :
|
286
|
+
|
287
|
+
wc_get_price_excluding_tax(
|
288
|
+
|
289
|
+
$product,
|
290
|
+
|
291
|
+
array(
|
292
|
+
|
293
|
+
'qty' => $qty,
|
294
|
+
|
295
|
+
'price' => $price,
|
296
|
+
|
297
|
+
'dollPrice' => $dollPrice,
|
298
|
+
|
299
|
+
)
|
300
|
+
|
301
|
+
);
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
```
|
306
|
+
|
307
|
+
お手数ですがご教示いただけましたら幸いです。
|
2
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,11 @@
|
|
22
22
|
|
23
23
|
<?php function get($hoge){
|
24
24
|
|
25
|
+
$num = intval($hoge);
|
26
|
+
|
25
|
-
ret
|
27
|
+
$result = $1.2* $num;
|
28
|
+
|
29
|
+
var_dump($result);
|
26
30
|
|
27
31
|
|
28
32
|
|
@@ -32,9 +36,15 @@
|
|
32
36
|
|
33
37
|
?>
|
34
38
|
|
35
|
-
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
|
39
|
+
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
|
36
40
|
|
41
|
+
<?php
|
42
|
+
|
43
|
+
echo $product->get_price_html();?><br>
|
44
|
+
|
45
|
+
<?php
|
46
|
+
|
37
|
-
echo get($product->get_price_html()); ?></p>
|
47
|
+
echo get($product->get_price_html()); ?></p>
|
38
48
|
|
39
49
|
```
|
40
50
|
|
1
32行目がどこか表記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,10 +34,10 @@
|
|
34
34
|
|
35
35
|
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>"><?php echo $product->get_price_html();
|
36
36
|
|
37
|
-
echo get($product->get_price_html()); ?></p>
|
37
|
+
echo get($product->get_price_html()); ?></p>//32行目
|
38
38
|
|
39
39
|
```
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
エラーメッセージ:Parse error: syntax error, unexpected ';', expecting ',' or ')on line 32とでてしまいます。
|
43
|
+
エラーメッセージ:Parse error: syntax error, unexpected ';', expecting ',' or ')on line 32とでてしまいます。特に間違った;は使っていないと思うのですが、、
|