function rcl_add_cart_button($content) { global $post, $rmag_options; if ($post->post_type !== 'products') { return $content; } $metas = rcl_get_postmeta_array($post->ID); $price = $metas['price-products']; $outsale = $metas['outsale']; $button = '<div class="price-basket-product">'; if (!$outsale) { if ($metas['availability_product'] == 'empty') { //если товар цифровой if ($price) { $button .= 'Цена: ' . rcl_get_price($post->ID) . ' <input type="text" size="2" name="number_product" id="number_product" value="1">'; } else { $button .= 'Бесплатно '; } $button .= rcl_get_button('Добавить в корзину', '#', array('icon' => false, 'class' => 'add_basket', 'attr' => 'onclick="rcl_add_cart(this);return false;" data-product=' . $post->ID)); } else { if ($rmag_options['products_warehouse_recall'] == 1) { $amount = get_post_meta($post->ID, 'amount_product', 1); if ($amount > 0 || $amount == false) { $button .= 'Цена: ' . rcl_get_price($post->ID) . ' <input type="text" size="2" name="number_product" id="number_product" value="1">' . rcl_get_button('Добавить в корзину', '#', array('icon' => false, 'class' => 'add_basket', 'attr' => 'onclick="rcl_add_cart(this);return false;" data-product=' . $post->ID)); } } else { $button .= 'Цена: ' . rcl_get_price($post->ID) . ' <input type="text" size="2" name="number_product" id="number_product" value="1">' . rcl_get_button('Добавить в корзину', '#', array('icon' => false, 'class' => 'add_basket', 'attr' => 'onclick="rcl_add_cart(this);return false;" data-product=' . $post->ID)); } } } $button .= '</div>'; $button = apply_filters('cart_button_product_page', $button); $content .= $button; return $content; }
function insert_order($order_id, $user_id = false) { global $wpdb, $user_ID, $rmag_options, $active_addons; if (!$user_id) { $user_id = $user_ID; } $cart = $_SESSION['cart']; $cart = apply_filters('cart_values_rcl', $cart); if (!$cart) { return false; } foreach ($cart as $prod_id => $val) { $status = 1; $metas = rcl_get_postmeta_array($prod_id); $price = $val['price']; if (isset($active_addons['users-market']) && $metas['availability_product'] == 'empty') { //если товар цифровой if (!$price) { $status = 3; } } else { if (!$price) { $status = 2; } $amount = $metas['amount_product']; if ($rmag_options['products_warehouse_recall'] == 1 && $amount) { //формируем резерв товара $reserve = $metas['reserve_product']; if ($reserve) { $reserve = $reserve + $val['number']; } else { $reserve = $val['number']; } $amount = $amount - $val['number']; update_post_meta($prod_id, 'amount_product', $amount); update_post_meta($prod_id, 'reserve_product', $reserve); } } $res = $wpdb->insert(RMAG_PREF . "orders_history", array('order_id' => $order_id, 'user_id' => $user_id, 'product_id' => $prod_id, 'product_price' => $price, 'numberproduct' => $val['number'], 'order_date' => current_time('mysql'), 'order_status' => $status)); } do_action('insert_order_rcl', $user_id, $order_id); session_destroy(); return $res; }