Home > Net >  How To Show Total Cart Order Amount In Desctiption Payment Method in WooCommerce
How To Show Total Cart Order Amount In Desctiption Payment Method in WooCommerce

Time:10-06

I want to add a HTML Description to a Payment Method in WooCommerce.

add_filter( 'woocommerce_gateway_description', 'rudr_change_payment_gateway_description', 25, 2 );
function rudr_change_payment_gateway_description( $description, $gateway_id ) {
    if( 'pec_gateway_check' === $gateway_id ) {
        ?>

    <div >
      <span >مبلغ پرداختی آنلاین شما:<span > <!--1 total order * 35% --> </span></span>
      <span >مبلغ چک صیادی:<span > <!--2 total order * 65% --> </span></span>
      <span >تاریخ چک صیادی:<span > <!--3 The date is 40 days later --> </span></span>
    </div>

    <?php
         $description = '';
    }
    return $description;
}

I want to display the total shopping cart in this description as below:

1- total order * 35% = amount $ (example= 35,000$)

2- total order * 65% = amount $ (example= 65,000$)

3- The date is 40 days later = today 40 days later (example= 2022/10/16)

CodePudding user response:

Try this code:

add_filter( 'woocommerce_gateway_description', 'rudr_change_payment_gateway_description', 25, 2 );
function rudr_change_payment_gateway_description( $description, $gateway_id ) {
    if( 'pec_gateway_check' === $gateway_id ) {
        global $woocommerce;
        $carttotal = $woocommerce->cart->total;
        
        
        ?>

    <div >
        <span >مبلغ پرداختی آنلاین شما:<span > <?php echo "35% is: " . number_format($carttotal*0.35, 2) . "$"; ?> </span></span>
      <span >مبلغ چک صیادی:<span > <?php echo "65% is: " .  number_format($carttotal*0.65, 2) . "$"; ?> </span></span>
        <span >تاریخ چک صیادی:<span > <?php echo "40 days later is: " .  date('Y/m/d', strtotime(" 40 days")); ?> </span></span>
    </div>

    <?php
         $description = '';
    }
    return $description;
}
  • Related