$order = wc_get_order($order_id_by_search_field);
$order->get_status();
function skip_cart_and_redirection_to_checkout() {
if (is_cart()) {
wp_redirect(wc_get_checkout_url());
// wp_redirect( WC()->cart->get_checkout_url() ); для WC < 3
}
}
add_action('template_redirect', 'skip_cart_and_redirection_to_checkout');
array( // WPCS: XSS ok.
'base' => $base,
'format' => $format,
'add_args' => false,
//'current' => max( 1, $current ),
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $total,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3,
)
$current_tags = get_the_terms( get_the_ID(), 'product_tag' );
//only start if we have some tags
if ( $current_tags && ! is_wp_error( $current_tags ) ) {
//create a list to hold our tags
echo '<ul class="product_tags">';
//for each tag we create a list item
foreach ($current_tags as $tag) {
$tag_title = $tag->name; // tag name
$tag_link = get_term_link( $tag );// tag archive link
echo '<li><a href="'.$tag_link.'">'.$tag_title.'</a></li>';
}
echo '</ul>';
}
// Store cart weight in the database
add_action('woocommerce_checkout_update_order_meta', 'woo_add_cart_weight');
function woo_add_cart_weight( $order_id ) {
global $woocommerce;
$weight = $woocommerce->cart->cart_contents_weight;
update_post_meta( $order_id, '_cart_weight', $weight );
}
// Add order new column in administration
add_filter( 'manage_edit-shop_order_columns', 'woo_order_weight_column', 20 );
function woo_order_weight_column( $columns ) {
$offset = 8;
$updated_columns = array_slice( $columns, 0, $offset, true) +
array( 'total_weight' => esc_html__( 'Weight', 'woocommerce' ) ) +
array_slice($columns, $offset, NULL, true);
return $updated_columns;
}
// Populate weight column
add_action( 'manage_shop_order_posts_custom_column', 'woo_custom_order_weight_column', 2 );
function woo_custom_order_weight_column( $column ) {
global $post;
if ( $column == 'total_weight' ) {
$weight = get_post_meta( $post->ID, '_cart_weight', true );
if ( $weight > 0 )
print $weight . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) );
else print 'N/A';
}
}
add_action( 'woocommerce_admin_order_totals_after_total', 'action_function_name_9670' );
function action_function_name_9670( $order_id ){
global $post;
$weight = get_post_meta( $post->ID, '_cart_weight', true );
print $weight . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) );
}
add_action( 'woocommerce_after_add_to_cart_button', 'remove_product' );
function remove_product() {
global $product;
$cart_item_key = WC()->cart->generate_cart_id( $product->get_ID() );
$in_cart = WC()->cart->find_product_in_cart( $cart_item_key );
$cart_item_remove_url = wc_get_cart_remove_url( $cart_item_key );
?>
<div class="col s4">
<a class="addtocart_link"
id ="add_to_cart"
title="add_to_cart"
data-product-id="<?php echo $product->get_ID(); ?>"
data-cart-item-key="<?php echo $cart_item_key; ?>">
<span class="action_box fa fa-plus"></span></a>
</div>
<?php
if ( $in_cart ) {
$quantities = WC()->cart->get_cart_item_quantities();
foreach ( $quantities as $key => $quantity ) {
if ( $product->get_ID() == $key ) {
if ( $quantity > 1 ) {
?>
<div class="col s4">
<a id="remove_one_item" class="remove_from_cart" href="#"
data-product-id="<?php echo $product->get_ID(); ?>"
data-in-cart-qty="<?php echo $quantity; ?>"
data-cart-item-key="<?php echo $cart_item_key; ?>"
title="remove_from_cart ">
<span class=" action_box fa fa-minus "></span></a>
</div>
<?php
return;
}
}
}
?>
<div class="col s4">
<a class="remove_from_cart" href="<?php echo esc_url( $cart_item_remove_url ); ?>" title="remove_from_cart ">
<span class=" action_box fa fa-minus "></span></a>
<?php
}
}
add_action( 'wp_footer', 'change_qty_script' );
function change_qty_script() {
?>
<script>
jQuery(document).ready(function ($) {
$('#remove_one_item').click(function () {
var current_qty = parseInt($(this).attr('data-in-cart-qty'));
var id = $(this).attr('data-product-id');
var cat_item_key = $(this).attr('data-cart-item-key');
var data = {
product_id: id,
quantity: current_qty - 1,
cat_item_key : cat_item_key
};
var url = wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'update_qty');
$.post(url, data, function (response) {
if (!response) {
return;
}
if (response) {
location.reload();
}
});
});
$('#add_to_cart').click(function () {
var id = $(this).attr('data-product-id');
var cat_item_key = $(this).attr('data-cart-item-key');
var data = {
product_id: id,
quantity: 1,
};
var url = wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart');
$.post(url, data, function (response) {
if (!response) {
return;
}
if (response) {
location.reload();
}
});
});
});
</script>
<?php
}
add_action( 'wc_ajax_update_qty', 'update_qty' );
function update_qty() {
ob_start();
$product_id = absint( $_POST['product_id'] );
$product = wc_get_product( $product_id );
$quantity = $_POST['quantity'];
$cat_item_key = $_POST['cat_item_key'];
WC()->cart->set_quantity( $cat_item_key, $quantity, true );
wp_send_json( 'done' );
}