Skip to content

Commit

Permalink
update function names
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEbabi committed Nov 8, 2020
1 parent ec9150b commit bc750a5
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// Display an action button in admin order list header
add_action( 'manage_posts_extra_tablenav', 'admin_order_list_top_bar_button', 20, 1 );
function admin_order_list_top_bar_button( $which ) {
global $pagenow, $typenow;
add_action( 'manage_posts_extra_tablenav', 'admin_order_list_top_combine_button', 20, 1 );

function admin_order_list_top_combine_button( $which ) {
global $pagenow, $typenow;
if ( 'shop_order' === $typenow && 'edit.php' === $pagenow && 'top' === $which ) {
?>
<div class="alignleft actions custom">
<input type='number' name='first_order' min=0 placeholder="Order No - 1">
<input type='number' name='second_order' min=0 placeholder="Order No - 2">
<button type="submit" name="combineOrders" style="height:32px;" class="button" value="yes"><?php
echo __( 'Combine Orders', 'woocommerce' ); ?></button>
</div>
<?php
$content = "<div class='alignleft actions custom'>
<input type='number' name='first_order' min=0 placeholder='Order ID - 1'>
<input type='number' name='second_order' min=0 placeholder='Order ID - 2'>
<button type='submit' name='combineOrders' style='height:32px;' class='button' value='yes'>Combine Orders</button>
</div>";
}
}

// Trigger an action (or run some code) when the button is pressed
add_action( 'restrict_manage_posts', 'display_admin_shop_order_language_filter' );
function display_admin_shop_order_language_filter() {
add_action( 'restrict_manage_posts', 'display_admin_shop_order_combine_orders' );

function display_admin_shop_order_combine_orders() {
global $pagenow, $typenow;

if ( 'shop_order' === $typenow && 'edit.php' === $pagenow &&
Expand All @@ -42,26 +38,23 @@ function display_admin_shop_order_language_filter() {
{
$product = wc_get_product($product_id);
$second_order->add_product($product, $product_quantity);
//wc_update_product_stock($product, $product_quantity, 'decrease');
}
//if product type is variable
else
{
$variation = wc_get_product($variation_id);
$second_order->add_product($variation, $product_quantity);
//wc_update_product_stock($variation, $product_quantity, 'decrease' );
}
}
$status = $second_order->get_status();
$second_order->calculate_totals();
$second_order->update_status('pending');
$second_order->update_status($status);
$first_order->update_status("cancelled", "Combined with order no: $second_order_id.");
$second_order->add_order_note("Combined with order no: $first_order_id.");
$first_order->update_status("cancelled", "This order is cancelled since it is combined with order ID: $second_order_id.");
$second_order->add_order_note("Order ID: $first_order_id is cancelled and combined with this order.");
}

$URL = get_admin_url();
$URL .= "edit.php?post_type=shop_order";
echo "<script>if(!alert('Order No: $first_order_id is cancelled and combined with Order No: $second_order_id.')){ window.location.href = '$URL'; }</script>";
echo "<script>if(!alert('Order ID: $first_order_id is cancelled and combined with Order ID: $second_order_id')){ window.location.href = '$URL'; }</script>";
}
}

0 comments on commit bc750a5

Please sign in to comment.