woocommerce/woocommerce

Pay for Order Link - Hot to check Stock

Fermée

#28 524 ouverte le 9 déc. 2020

 (2 commentaires) (0 réaction) (0 personne assignée)PHP (10 695 forks)batch import
Good First IssueOrder ManagementProduct/Inventory ManagementRubikplugin: woocommerce

Métriques du dépôt

Stars
 (10 294 étoiles)
Métriques de merge PR
 (Merge moyen 9j 12h) (423 PRs mergées en 30 j)

Description

Is your feature request related to a problem? Please describe. Some shop owners like to have the payment link available on other order statuses besides "pending" so they use the "woocommerce_valid_order_statuses_for_payment" hook like this (for example):

add_action( 'woocommerce_valid_order_statuses_for_payment', function( $statuses, $order ) { $statuses[] = 'on-hold'; return $statuses; }, 10, 2 );

This allows shop owners to send a payment link for a client for a variety of orders statuses if the order is not paid, the order can have the stock reduced or not depending on how the shop owner did the set up or how the payment gateway that created the order works. The problem with this is that the "class-wc-shortcode-checkout.php" file on line 126 makes a check for stock that is not appropriate. That line will check if stock is available because the order could be a failed one but the way it checks is not looking for a failed status but checking if the order is not a pending one (it checks by exclusion). If one adds a new order statuses via "woocommerce_valid_order_statuses_for_payment" it will always check for stock even for orders that have already reduced stock.

Describe the solution you'd like The solution seems simple, do not check for the order status, just make a check if the stock has been reduced, if it was not then check for availability. Like this:

  • Order or payment link is invalid.
  • Logged out customer does not have permission to pay for this order
  • Add notice if logged in customer is trying to pay for guest order.
  • Logged in customer trying to pay for someone else's order.
  • Does not need payment.
  • ### Check for stock availability if the stock has not been reduced

Replace

if ( ! $order->has_status( wc_get_is_pending_statuses() ) ) {

With

if (get_post_meta( $order->id, '_order_stock_reduced', true ) != 'yes') {

Additional context This check has to be less specific and then it will work for failed orders and for other type of orders.

  • Is the link valid? (Order ID, Hash, etc.)
  • Can the user pay for this order?
  • Is the order Paid?
  • Is there stock? (Check if stock was reduced, if not then check for stock)

If everything is ok then go ahead and show the form.

Guide contributeur