Customers must confirm a contract for each order when purchasing products. Customers cannot purchase the product without confirming this agreement.
I created a checkbox for this on the checkout page. After customers confirm this, they buy the product. I save the approved contracts to the database. I can find it with the order number. So far, no problem.
On the My Account page, I created a new section (eg orders): Contracts. From here, every customer can access the contracts. However, I cannot access the contracts from this section that I have created. Because I can't get the order id.
Can I reach the order number with the current user id? I couldn't find any results for this. Or is there a different way?
<?php
class WooContractMyAccount
{
private $MyAccountContractsEndPoint = 'registered-contracts ';
public function __construct()
{
add_filter('woocommerce_account_menu_items', array($this, 'MyAccountRegistredContracts'), 10, 1);
add_action('woocommerce_account_' . $this->MyAccountContractsEndPoint . '_endpoint', array($this, 'MyAccountRegistredContractsEndPoint'), 10, 1);
add_action('init', array($this, 'WooContractInit'));
}
public function MyAccountRegistredContracts($items)
{
$items = array($this->MyAccountContractsEndPoint => __('Registered Contracts')) + $items;
return $items;
}
public function WooContractInit()
{
add_rewrite_endpoint($this->MyAccountContractsEndPoint, EP_ROOT | EP_PAGES);
}
}
public function MyAccountRegistredContractsEndPoint()
{
global $wpdb;
$table = $wpdb->prefix . 'registered_contracts';
$table_contracts = $wpdb->prefix . 'contracts';
////The problem is here! ($contracts)
$contracts = $wpdb->get_results($wpdb->prepare("SELECT contracts.name,registeredcontracts.date,registeredcontracts.file FROM $table registeredcontracts
left join $table_contracts contracts ON contracts.id=registeredcontracts.contracts WHERE ref = %d", _______order id must be written_______));
?><div class="woocommerce-MyAccount-content">
<?php if (count($contracts) > 0) : ?>
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<th class="woocommerce-orders-table__header">
<?php _e('Contract') ?>
</th>
<th class="woocommerce-orders-table__header">
<?php _e('Date') ?>
</th>
<th class="woocommerce-orders-table__header">
<?php _e('File') ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($contracts as $contract) : ?>
<tr>
<td><?php _e($contract->name); ?></td>
<td><?php echo $contract->date; ?></td>
<td><a href="<?php echo CONTRACT_URL . '/' . $contract->file; ?>" target="_blank" class="woocommerce-button button"><?php _e('Download Contract'); ?></a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p><?php _e('You do not have a registered contract. ') ?></p>
<?php endif; ?>
</div>
<?php
}