'Substraction in woocommerce
my problem is as follows. I am currently generating a tax receipt for some orders (not all) in my woocommerce. but the customer would like for 3 of the 4 products to be priced at €60. Outside in the shop it is for example 110. Can we make a subtraction on certain product id when the user generates his receipt? here is part of my calculation function. Thanks for help ^^
add_action( 'init', 'silva_add_endpoint' );
function silva_add_endpoint() {
// WP_Rewrite is my Achilles' heel, so please do not ask me for detailed explanation
add_rewrite_endpoint( 'tax-receipt', EP_PAGES );
}
/*
* Part 3. Content for the new page in My Account, woocommerce_account_{ENDPOINT NAME}_endpoint
*/
add_action( 'woocommerce_account_tax-receipt_endpoint', 'silva_my_account_endpoint_content' );
function silva_my_account_endpoint_content() {
// GET CURR USER
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) return;
// GET USER ORDERS (COMPLETED + PROCESSING)
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $current_user->ID,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_is_paid_statuses() ),
) );
// LOOP THROUGH ORDERS AND GET PRODUCT IDS
if ( ! $customer_orders ) return;
$product_ids = array();
?>
<div class="donate">
<h4>Reçu fiscal</h4>
<h5>Par année</h5>
<h6 style="font-weight:bold;"><span style="color:red;">Attention :</span> si vous avez réglé votre don et/ou votre adhésion avec différents moyens de paiement, vous devez télécharger vos reçus fiscaux individuellement pour chaque transaction en cliquant sur le bouton «Télécharger» dans la colonne «Téléchargement» ci-dessous.</h6>
<h6>2021 <a href="https://union-rationaliste.org/year-download-pdf/?id=2021" style="border: solid 1px; padding: 7px 10px; margin-left: 22px;">Télécharger le reçu de l'année complète</a></h6>
<table>
<th>Numéro de reçu</th>
<th>Prénom</th>
<th>Nom de famille</th>
<th>E-mail</th>
<th>Téléphoner</th>
<th>Code postal</th>
<th>Téléchargement</th>
<?php
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order->ID );
$year = explode('-',$order->get_date_created());
if($year[0]=='2021'){
$items = $order->get_items();
foreach ( $items as $item ) {
//print_r($customer_order);
$product_id = $item->get_product_id();
$product_ids[] = $product_id;
if(in_array(1708, $product_ids) || in_array(1724, $product_ids) || in_array(1742, $product_ids) || in_array(1758, $product_ids) || in_array(9463, $product_ids)){
?>
<tr>
<td>#<?php echo $order->id; ?></td>
<td><?php echo $order->get_billing_first_name(); ?></td>
<td><?php echo $order->get_billing_last_name(); ?></td>
<td><?php echo $order->get_billing_email(); ?></td>
<td><?php echo $order->get_billing_phone(); ?></td>
<td><?php echo $order->get_billing_postcode(); ?></td>
<td><a href="https://union-rationaliste.org/download-pdf/?id=<?php echo $order->id; ?>">Télécharger</a></td>
</tr>
<?php
//print_r($order);
}
}
}
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|