0

I'm trying to get a php file of a plugin that has been discontinued for three years to work, and not being a programmer I'm not succeeding .. In practice, once the price has been extracted from the woocommerce cart, I want it to be used to update the price on a QR code generator. The first part works, the second part works as well, but I can't get the "amount" parameter to read the $ total value. Thanks to who will help me.

// 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;
  }

1 Answer 1

1

Welcome!

Well, that's very easy. You only have to provide your call to "shortcode_qrcode( $atts = [] )" with the parameter atts, an array containing your "amount" so that it gets replaced with your value for total.

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)
        }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.