Untitled
unknown
plain_text
2 years ago
1.5 kB
11
Indexable
function add_my_account_order_actions( $actions, $order ) {
if ( ! $order || ! $order->has_status( apply_filters( 'marketking_valid_statuses_refunds', array( 'wc-pcompany', 'pcompany' ) ) ) || ! is_user_logged_in() ) {
return $actions;
}
// if this user is a subaccount, do not show the button
$currentuserid = get_current_user_id();
$account_type = get_user_meta($currentuserid,'b2bking_account_type', true);
if ($account_type === 'subaccount'){
?>
<div>
<input type="hidden" class="b2bking_order_number" value="<?php echo esc_attr($order->get_id());?>">
<a class="woocommerce-button button b2bking_cancel_order">Cancel</a>
</div>
<?php
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_order_actions', 10, 2 );
add_action('wp_head', function(){
?>
<script>
jQuery(document).ready(function(){
jQuery('.b2bking_cancel_order').on('click', function(){ // when subaccount cancels order
let orderid = jQuery(this).parent().find('.b2bking_order_number').val();
if (confirm(b2bking_display_settings.cancel_order_confirm)){
var datavar = {
action: 'b2bking_reject_order',
security: b2bking_display_settings.security,
orderid: orderid,
reason: ''
};
jQuery.post(b2bking_display_settings.ajaxurl, datavar, function(response){
location.reload();
});
}
});
});
</script>
<?php
});Editor is loading...