在函数或数组中使用变量

阿瓦隆记录

我正在尝试获取一个已停止工作三年的插件的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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在函数中使用变量

来自分类Dev

在多个函数中使用变量?

来自分类Dev

在.query函数中使用变量

来自分类Dev

在匿名函数.on中使用变量

来自分类Dev

在函数中使用for循环变量

来自分类Dev

在KSH函数中使用变量

来自分类Dev

在SetTimer函数中使用变量

来自分类Dev

在函数中使用共享变量

来自分类Dev

在Polymer函数中使用变量

来自分类Dev

在匿名函数中使用变量

来自分类Dev

在php数组中使用变量

来自分类Dev

在函数中使用结构数组?

来自分类Dev

如何在OpenCL内核中使用多个用户定义的函数共享全局变量(数组)

来自分类Dev

如何在此重复函数中使用数组而不是变量?

来自分类Dev

如何在.then中使用函数变量?

来自分类Dev

在python函数中使用全局变量

来自分类Dev

如何在匿名函数中使用变量?

来自分类Dev

在jQuery中的函数中使用多变量

来自分类Dev

在函数中使用声明中的类型变量

来自分类Dev

javascript复制变量以在函数中使用

来自分类Dev

在SAS用户定义函数中使用变量

来自分类Dev

在PHP公共php函数中使用变量

来自分类Dev

如何在函数中使用外部变量?

来自分类Dev

在r中使用变量作为函数参数

来自分类Dev

在连续的Ajax函数中使用相同的变量

来自分类Dev

在R中的函数中使用变量

来自分类Dev

如何在函数中使用类变量?

来自分类Dev

c ++在非类函数中使用类变量

来自分类Dev

在Python函数中使用变量作为参数