我正在尝试获取一个已停止工作三年的插件的php文件,并且由于不是程序员,所以我没有成功..实际上,一旦从woocommerce购物车中提取了价格,我想用于更新QR码生成器上的价格。第一部分起作用,第二部分也起作用,但是我无法获得“金额”参数来读取$总值。感谢谁会帮助我。
// WooCommerce
add_action( 'woocommerce_order_details_after_order_table', array( $this, 'order_details_after_order_table' ) );
}
/**
* @todo refactor
*
* @param WC_Order $order
*/
public function order_details_after_order_table( $order ) {
$payment_method = $order->get_payment_method();
$total = $order->get_total();
if ( $payment_method === 'bacs' ) {
// temporary
echo $this->shortcode_qrcode();
echo $total; // correct return value (626)
}
}
public function shortcode_qrcode( $atts = [] ) {
$options = $this->options;
// custom param
$custom = shortcode_atts( array(
'id' => $options[ $this->field_key->field_promptpay_id ],
'amount' => 0 // I want use the $total in this point
), $atts );
$html = sprintf( '<div class="ppy-card"
data-promptpay-id="%s"
data-amount="%f"
data-show-promptpay-logo="%s"
data-show-promptpay-id="%s"
data-account-name="%s"
data-shop-name="%s"
data-card-style="%s"
></div>',
$custom['id'],
$custom['amount'],
$options[ $this->field_key->field_show_promptpay_logo ],
$options[ $this->field_key->field_show_promptpay_id ],
$options[ $this->field_key->field_account_name ],
$options[ $this->field_key->field_shop_name ],
1
);
return $html;
}
欢迎!
好吧,这很容易。您只需提供带有参数atts的对“ shortcode_qrcode($ atts = [])”的调用,该数组包含您的“金额”,以便将其替换为总计值。
public function order_details_after_order_table( $order ) {
$payment_method = $order->get_payment_method();
$total = $order->get_total();
if ( $payment_method === 'bacs' ) {
// temporary
echo $this->shortcode_qrcode(array("amount"=>$total)); // this would be the change to make
echo $total; // correct return value (626)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句