質問編集履歴
4
コードの余計な記号を消去
title
CHANGED
File without changes
|
body
CHANGED
@@ -125,7 +125,7 @@
|
|
125
125
|
array(
|
126
126
|
'qty' => 1,
|
127
127
|
'price' => $product->get_price(),
|
128
|
-
'dollPrice' =>intval($product->get_price()) / 1.2
|
128
|
+
'dollPrice' =>intval($product->get_price()) / 1.2,
|
129
129
|
)
|
130
130
|
);
|
131
131
|
$price = $args['price'];
|
3
質問内容の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,27 +1,154 @@
|
|
1
|
-
|
1
|
+
### 前提・実現したいこと
|
2
|
-
|
2
|
+
$product->get_dollPrice_html()の値を1.2で割りたい。そこでwc_get_price_to_displayの連想配列に'price'を1.2で割った'dollPrice' => $dollPriceを追加して解決しようと試みた。
|
3
|
+
|
4
|
+
### 発生している問題・エラーメッセージ
|
3
|
-
|
5
|
+
自分で作った$product->get_dollPrice_html()(詳細は該当のコードエリアにて)で出力した結果が、既存の$product->get_price_html()で出力した結果と変わらない。
|
6
|
+
|
7
|
+
|
8
|
+
### 試したこと
|
9
|
+
get_price_html()を見てみると以下の記述があった。
|
4
10
|
```php
|
5
|
-
|
11
|
+
public function get_price_html( $deprecated = '' ) {
|
6
|
-
|
12
|
+
if ( '' === $this->get_price() ) {
|
13
|
+
$price = apply_filters( 'woocommerce_empty_price_html', '', $this );
|
14
|
+
} elseif ( $this->is_on_sale() ) {
|
15
|
+
$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();
|
16
|
+
} else {
|
17
|
+
$price = wc_price( wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
7
|
-
}
|
18
|
+
}
|
8
19
|
|
9
|
-
|
20
|
+
return apply_filters( 'woocommerce_get_price_html', $price, $this );
|
21
|
+
}
|
22
|
+
```
|
23
|
+
自分の状況はelseの場合のみしかないのでwc_price()とwc_get_price_to_display()のみを考え、それらの内容は以下の通りだった。
|
10
24
|
|
11
|
-
|
25
|
+
```php
|
12
|
-
|
26
|
+
function wc_price( $price, $args = array() ) {
|
13
|
-
$
|
27
|
+
$args = apply_filters(
|
14
|
-
|
28
|
+
'wc_price_args',
|
15
|
-
|
29
|
+
wp_parse_args(
|
30
|
+
$args,
|
31
|
+
array(
|
32
|
+
'ex_tax_label' => false,
|
33
|
+
'currency' => '',
|
34
|
+
'decimal_separator' => wc_get_price_decimal_separator(),
|
35
|
+
'thousand_separator' => wc_get_price_thousand_separator(),
|
36
|
+
'decimals' => wc_get_price_decimals(),
|
37
|
+
'price_format' => get_woocommerce_price_format(),
|
38
|
+
)
|
39
|
+
)
|
40
|
+
);
|
16
41
|
|
42
|
+
$unformatted_price = $price;
|
43
|
+
$negative = $price < 0;
|
44
|
+
$price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );
|
45
|
+
$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'] );
|
46
|
+
|
47
|
+
if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $args['decimals'] > 0 ) {
|
48
|
+
$price = wc_trim_zeros( $price );
|
49
|
+
}
|
50
|
+
|
51
|
+
$formatted_price = ( $negative ? '-' : '' ) . sprintf( $args['price_format'], '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $args['currency'] ) . '</span>', $price );
|
52
|
+
$return = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';
|
53
|
+
|
54
|
+
if ( $args['ex_tax_label'] && wc_tax_enabled() ) {
|
55
|
+
$return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Filters the string of price markup.
|
61
|
+
*
|
62
|
+
* @param string $return Price HTML markup.
|
63
|
+
* @param string $price Formatted price.
|
64
|
+
* @param array $args Pass on the args.
|
65
|
+
* @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0.
|
66
|
+
*/
|
67
|
+
return apply_filters( 'wc_price', $return, $price, $args, $unformatted_price );
|
17
68
|
}
|
69
|
+
```
|
70
|
+
```php
|
71
|
+
function wc_get_price_to_display( $product, $args = array() ) {
|
72
|
+
$args = wp_parse_args(
|
73
|
+
$args,
|
74
|
+
array(
|
75
|
+
'qty' => 1,
|
76
|
+
'price' => $product->get_price(),
|
77
|
+
|
78
|
+
)
|
79
|
+
);
|
80
|
+
$price = $args['price'];
|
81
|
+
$qty = $args['qty'];
|
18
82
|
|
19
|
-
?>
|
20
|
-
|
83
|
+
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
|
21
|
-
<?php
|
22
|
-
|
84
|
+
wc_get_price_including_tax(
|
23
|
-
|
85
|
+
$product,
|
86
|
+
array(
|
87
|
+
'qty' => $qty,
|
88
|
+
'price' => $price,
|
89
|
+
|
90
|
+
)
|
91
|
+
) :
|
24
|
-
|
92
|
+
wc_get_price_excluding_tax(
|
93
|
+
$product,
|
94
|
+
array(
|
95
|
+
'qty' => $qty,
|
96
|
+
'price' => $price,
|
97
|
+
|
98
|
+
)
|
99
|
+
);
|
100
|
+
}
|
101
|
+
|
25
102
|
```
|
26
103
|
|
104
|
+
### 該当のソースコード
|
105
|
+
新たに自分で作ったget_dollPrice_html()のコード
|
106
|
+
```php
|
107
|
+
public function get_dollPrice_html( $deprecated = '' ) {
|
108
|
+
if ( '' === $this->get_price() ) {
|
27
|
-
|
109
|
+
$dollPrice = apply_filters( 'woocommerce_empty_price_html', '', $this );
|
110
|
+
} elseif ( $this->is_on_sale() ) {
|
111
|
+
$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();
|
112
|
+
} else {
|
113
|
+
$dollPrice = wc_price( wc_get_price_to_display( $this ) ) . $this->get_price_suffix();
|
114
|
+
}
|
115
|
+
|
116
|
+
return apply_filters( 'woocommerce_get_price_html', $dollPrice, $this );
|
117
|
+
}
|
118
|
+
```
|
119
|
+
|
120
|
+
改変したwc_get_price_to_display()
|
121
|
+
```php
|
122
|
+
function wc_get_price_to_display( $product, $args = array() ) {
|
123
|
+
$args = wp_parse_args(
|
124
|
+
$args,
|
125
|
+
array(
|
126
|
+
'qty' => 1,
|
127
|
+
'price' => $product->get_price(),
|
128
|
+
'dollPrice' =>intval($product->get_price()) / 1.2;
|
129
|
+
)
|
130
|
+
);
|
131
|
+
$price = $args['price'];
|
132
|
+
$qty = $args['qty'];
|
133
|
+
$dollPrice = $arg['dollPrice'];
|
134
|
+
|
135
|
+
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
|
136
|
+
wc_get_price_including_tax(
|
137
|
+
$product,
|
138
|
+
array(
|
139
|
+
'qty' => $qty,
|
140
|
+
'price' => $price,
|
141
|
+
'dollPrice' => $dollPrice,
|
142
|
+
)
|
143
|
+
) :
|
144
|
+
wc_get_price_excluding_tax(
|
145
|
+
$product,
|
146
|
+
array(
|
147
|
+
'qty' => $qty,
|
148
|
+
'price' => $price,
|
149
|
+
'dollPrice' => $dollPrice,
|
150
|
+
)
|
151
|
+
);
|
152
|
+
}
|
153
|
+
```
|
154
|
+
お手数ですがご教示いただけましたら幸いです。
|
2
コードの編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,13 +10,18 @@
|
|
10
10
|
|
11
11
|
?>
|
12
12
|
<?php function get($hoge){
|
13
|
+
$num = intval($hoge);
|
13
|
-
|
14
|
+
$result = $1.2* $num;
|
15
|
+
var_dump($result);
|
14
16
|
|
15
17
|
}
|
16
18
|
|
17
19
|
?>
|
18
|
-
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
|
20
|
+
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
|
21
|
+
<?php
|
22
|
+
echo $product->get_price_html();?><br>
|
23
|
+
<?php
|
19
|
-
echo get($product->get_price_html()); ?></p>
|
24
|
+
echo get($product->get_price_html()); ?></p>
|
20
25
|
```
|
21
26
|
|
22
27
|
エラーメッセージ:Parse error: syntax error, unexpected ';', expecting ',' or ')on line 32とでてしまいます。特に間違った;は使っていないと思うのですが、、
|
1
32行目がどこか表記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
?>
|
18
18
|
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>"><?php echo $product->get_price_html();
|
19
|
-
echo get($product->get_price_html()); ?></p>
|
19
|
+
echo get($product->get_price_html()); ?></p>//32行目
|
20
20
|
```
|
21
21
|
|
22
|
-
エラーメッセージ:Parse error: syntax error, unexpected ';', expecting ',' or ')on line 32とでてしまいます。
|
22
|
+
エラーメッセージ:Parse error: syntax error, unexpected ';', expecting ',' or ')on line 32とでてしまいます。特に間違った;は使っていないと思うのですが、、
|