public function is_bulk_variation_form() { global $post; if (!$post) { return false; } /** Remove validation (_bv_type) -- 03/02/2016 **/ if (!is_product()) { return false; } /****/ /** Validate if exits role -- 03/02/2016 **/ if ($this->role_exists('wholesale_customer')) { if (!current_user_can('wholesale_customer')) { return false; } } // 2.0 Compat if (function_exists('get_product')) { $product = get_product($post->ID); } else { $product = new WC_Product($post->ID); } if ($product && !$product->has_child() && !$product->is_type('variable')) { return false; } return apply_filters('woocommerce_bv_render_form', true); }
public static function update_orders_value( $post_id, $post ) { if ( is_int( wp_is_post_revision( $post_id ) ) ) return; if ( is_int( wp_is_post_autosave( $post_id ) ) ) return; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; if ( $post->post_type != 'product' ) return $post_id; if ( version_compare( WC()->version, '2.2.0', '<' ) ) { $product = get_product( $post ); } else { $product = wc_get_product( $post ); } if ( $product ) { if ( $product->is_on_sale() ) { update_post_meta( $post_id, '_psad_onsale_order', 2 ); } else { update_post_meta( $post_id, '_psad_onsale_order', 1 ); } if ( $product->is_featured() ) { update_post_meta( $post_id, '_psad_featured_order', 2 ); } else { update_post_meta( $post_id, '_psad_featured_order', 1 ); } } }
/** * Build the "Add to cart" HTML. * * @param string $url * @param string $stock_status * @param string $type * @return string * @static * @since 1.0.0 */ public static function add_to_cart_button($product_id, $stock_status) { global $yith_wcwl; if (function_exists('get_product')) { $product = get_product($product_id); } else { $product = new WC_Product($product_id); } $url = $product->product_type == 'external' ? $yith_wcwl->get_affiliate_product_url($product_id) : $yith_wcwl->get_addtocart_url($product_id); $label_option = get_option('yith_wcwl_add_to_cart_text'); $localize_label = function_exists('icl_translate') ? icl_translate('Plugins', 'plugin_yit_wishlist_button', $label_option) : $label_option; $label = $product->product_type == 'variable' ? apply_filters('variable_add_to_cart_text', __('Choose an option', 'yit')) : apply_filters('yith_wcwl_add_to_cart_label', $localize_label); $icon = get_option('yith_wcwl_use_button') == 'yes' && get_option('yith_wcwl_add_to_cart_icon') != 'none' ? '<i class="' . get_option('yith_wcwl_add_to_cart_icon') . '"></i>' : ''; $cartlink = ''; $redirect_to_cart = get_option('yith_wcwl_redirect_cart') == 'yes' && $product->product_type != 'variable' ? 'true' : 'false'; $style = ''; //indicates the style (background-color and font color) if (get_option('yith_wcwl_use_button') == 'yes') { if ($product->product_type == 'external') { $cartlink .= '<a target="_blank" class="add_to_cart button alt button green standar-nowidth" href="' . $url . '"'; } else { $js_action = esc_attr('check_for_stock(\'' . $url . '\',\'' . $stock_status . '\',\'' . $redirect_to_cart . '\');'); $cartlink .= '<a class="add_to_cart button alt button green standar-nowidth" onclick="' . $js_action . '"'; } $cartlink .= $style . '>' . $icon . $label . '</a>'; } else { if ($product->product_type == 'external') { $cartlink .= '<a target="_blank" class="add_to_cart button alt button green standar-nowidth" href="' . $url . '">' . $icon . $label . '</a>'; } else { $js_action = esc_attr('check_for_stock(\'' . $url . '\',\'' . $stock_status . '\',\'' . $redirect_to_cart . '\');'); $cartlink .= '<a class="add_to_cart button alt button green standar-nowidth" href="javascript:void(0);" onclick="' . $js_action . '">' . $icon . $label . '</a>'; } } return $cartlink; }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $db; global $config; if (is_array($vars['product_id'])) { $p = $db->get_payment($payment_id); $price_count = 0; foreach ($p['data'][0]['BASKET_PRICES'] as $pp) { if ($pp) { $price_count++; } } if ($price_count > 1) { return "Only 1 paid product can be selected"; } $product_id = $vars['product_id'][0]; } $product =& get_product($product_id); $vars = array('email' => $this->config['business'], 'amount' => $price, 'ordernumber' => $payment_id, 'description' => $product->config['title'], 'returnurl' => sprintf("%s/thanks.php?member_id=%d&product_id=%d&payment_id=%d", $config['root_url'], $member_id, $product_id, $payment_id)); //encode and send $vars1 = array(); foreach ($vars as $kk => $vv) { $v = urlencode($vv); $k = urlencode($kk); $vars1[] = "{$k}={$v}"; } $vars = join('&', $vars1); if ($this->config['testing']) { html_redirect("https://demo.nochex.com/nochex.dll/checkout?{$vars}"); } else { html_redirect("https://www.nochex.com/nochex.dll/checkout?{$vars}"); } exit; }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $config, $db; $products = $product_id; $orig_product_id = $product_id; if (is_array($product_id)) { $product_id = $product_id[0]; } $product =& get_product($product_id); if (count($orig_product_id) > 1) { $product->config['title'] = $config['multi_title']; } $member = $db->get_user($member_id); $vars = array('merchant' => $this->config['merchant'], 'merchantemail' => $config['admin_email'], 'orderref' => $payment_id, 'orderinfo' => $product->config['title'], 'amount' => sprintf('%d', $price), 'name' => $member['name_f'] . ' ' . $member['name_l'], 'address' => $member['street'], 'postcode' => $member['zip'], 'town' => $member['city'], 'county' => $member['state'], 'country' => $member['country'], 'email' => $member['email'], 'phone' => $member['data']['phone'], 'requiredfields' => 'orderref,name,email', 'customeremail' => 1, 'callbackurl' => 1); // add currency code if (strlen($product->config['securetrading_currency'])) { $vars['currency'] = $product->config['securetrading_currency']; } else { $vars['currency'] = 'USD'; } $vars1 = array(); foreach ($vars as $kk => $vv) { $v = urlencode($vv); $k = urlencode($kk); $vars1[] = "{$k}={$v}"; } $vars = join('&', $vars1); header("Location: https://securetrading.net/authorize/form.cgi?{$vars}"); exit; }
public static function woocommerce_grouped_price_html($price, $product) { $tax_display_mode = get_option('woocommerce_tax_display_shop'); $child_prices = array(); foreach ($product->get_children() as $child_id) { //$child_prices[] = get_post_meta( $child_id, '_price', true ); $child = get_product($child_id); $child_prices[] = $child->get_price(); } $child_prices = array_unique($child_prices); $get_price_method = 'get_price_' . $tax_display_mode . 'uding_tax'; if (!empty($child_prices)) { $min_price = min($child_prices); $max_price = max($child_prices); } else { $min_price = ''; $max_price = ''; } if ($min_price) { if ($min_price == $max_price) { $display_price = wc_price($product->{$get_price_method}(1, $min_price)); } else { $from = wc_price($product->{$get_price_method}(1, $min_price)); $to = wc_price($product->{$get_price_method}(1, $max_price)); $display_price = sprintf(_x('%1$s–%2$s', 'Price range: from-to', 'woocommerce'), $from, $to); } $price = $display_price . $product->get_price_suffix(); } return $price; }
/** * Make Shortcode * * @package WooCommerce 360° Image * @author Captain Theme <*****@*****.**> * @since 1.0.0 */ public function shortcode($atts) { // Load in an instance of the WC_360_Image_Display Class $image_display = new WC_360_Image_Display(); // Array of default dimensions (used when shortcode doesn't define any) $dimensions = $image_display->default_width(); $default_width = $dimensions; // Shortcode Attributes extract(shortcode_atts(array('width' => $default_width, 'height' => '', 'id' => ''), $atts)); // If ID passed use that, if not get the current page's ID if ($id) { $id = $id; } else { $id = get_the_ID(); } // Enqueue the JS / CSS we need wp_enqueue_script('jquery'); wp_enqueue_script('wc360-threesixty-js'); wp_enqueue_script('wc360-threesixty-fullscreen-js'); wp_enqueue_style('wc360-threesixty-css'); wp_enqueue_script('wc360-js'); wp_enqueue_style('wc360-css'); wp_localize_script('wc360-js', 'wc360_vars', $image_display->js_data_all($width, $height, $id)); // Start Shortcode Output ob_start(); // We can only currently have one instance of the rotator per page, so only show it if the 'Replace Image with 360 Image' is unchecked if (!get_post_meta(get_the_ID(), 'wc360_enable', true)) { // Only continue if the ID received is a product if (get_post_type($id) == 'product') { $product = get_product($id); $attachment_ids = $product->get_gallery_attachment_ids(); // Only continue if there are gallery images if ($attachment_ids) { do_action('wc360_shortcode_before_image'); $content = '<div id="container" class="wc360-container shortcode" style="width:' . $width . 'px">'; $content .= '<div class="wc360 threesixty">'; $content .= '<div class="spinner">'; $content .= '<span>0%</span>'; $content .= '</div>'; $content .= '<ol class="threesixty_images"></ol>'; $content .= '</div>'; $content .= '</div>'; echo apply_filters('wc360_shortcode_image_output', $content); do_action('wc360_shortcode_after_image'); } else { // Error echo sprintf(__('%s There are no gallery images for this product!', 'woocommerce-360-image'), '<strong>' . __('Note:', 'woocommerce-360-image') . '</strong>'); } } else { // Error echo sprintf(__('%s This is not a valid product ID!', 'woocommerce-360-image'), '<strong>' . __('Note:', 'woocommerce-360-image') . '</strong>'); } } else { // Error echo sprintf(__('%s There can only be one rotator per page!', 'woocommerce-360-image'), '<strong>' . __('Note:', 'woocommerce-360-image') . '</strong>'); } $data = ob_get_clean(); // End Shortcode Output return $data; }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $config; global $db; $product =& get_product($product_id); if (!$product->config['is_recurring']) { return $this->do_not_recurring_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, $vars); } $varsx = array('product_id' => $product->config['twocheckout_id'], 'sid' => $this->config['seller_id'], 'amem_payment_id' => $payment_id, 'verify' => md5($this->config['seller_id'] . $product->config['twocheckout_id'] . $price), 'c_prod' => $product_id, 'id_type' => 1, 'c_name' => $product->config['title'], 'c_description' => $product->config['title'], 'c_price' => $price, 'c_tangible' => 'N', 'merchant_order_id' => $payment_id); $varsx['recuring'] = 'Y'; //if ($this->config['demo'] == 'Y') // $varsx['demo'] = 'Y'; $vars1 = array(); foreach ($varsx as $kk => $vv) { $v = urlencode($vv); $k = urlencode($kk); $vars1[] = "{$kk}={$vv}"; } $varsx = join('&', $vars1); if ($this->config['seller_id'] >= 200000 || $this->config['use_v2']) { header($s = "Location: https://www2.2checkout.com/2co/buyer/purchase?fixed=Y&" . $varsx); } else { header($s = "Location: https://www.2checkout.com/cgi-bin/crbuyers/recpurchase.2c?" . $varsx); } return ''; }
function cart_get_items() { $items = array(); foreach ($_SESSION['cart'] as $product_id => $quantity) { // Get product data from db $product = get_product($product_id); $list_price = $product['listPrice']; $discount_percent = $product['discountPercent']; $quantity = intval($quantity); // Calculate discount $discount_amount = round($list_price * ($discount_percent / 100.0), 2); $unit_price = $list_price - $discount_amount; $line_price = round($unit_price * $quantity, 2); // Store data in items array $items[$product_id]['name'] = $product['productName']; $items[$product_id]['description'] = $product['description']; $items[$product_id]['list_price'] = $list_price; $items[$product_id]['discount_percent'] = $discount_percent; $items[$product_id]['discount_amount'] = $discount_amount; $items[$product_id]['unit_price'] = $unit_price; $items[$product_id]['quantity'] = $quantity; $items[$product_id]['line_price'] = $line_price; } return $items; }
/** * Displays the Installments on the product page. * * @return string Price in 3 installments. */ function cs_product_parceled_single() { $product = get_product(); ?> <div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <p style="margin: 0;" itemprop="price" class="price"> <?php echo $product->get_price_html(); ?> </p> <p> <span style="color: #666; font-size: 100%" class="price"><?php _e('ou até 3x de'); ?> <?php echo cs_product_parceled(); ?> </span> </p> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?> " /> <link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?> " /> </div> <?php }
public function validate_add_cart_item($passed, $product_id, $qty) { $product = get_product($product_id); if ($product->product_type !== 'trip') { return $passed; } $stockOk = false; foreach ($this->package_types as $package) { if (isset($_POST['wc_trip_' . $package . "_package"])) { $post = $_POST['wc_trip_' . $package . "_package"]; $stockCheck = $product->check_package_stock($package, $post); if ($stockCheck) { $stockOk = true; } else { wc_add_notice("Sorry, " . $post . " is out of stock", 'error'); return false; } } } if ($stockOk) { return true; } else { wc_add_notice("Couldn't find specified packages, try again", 'error'); return false; } }
/** * Handle a renewal url */ public function renew_handler() { if (!empty($_GET['renew_licence']) && is_user_logged_in()) { global $wpdb; $licence_key = sanitize_text_field($_GET['renew_licence']); $licence = $wpdb->get_row($wpdb->prepare("\n\t\t\t\tSELECT * FROM {$wpdb->prefix}wp_plugin_licencing_licences\n\t\t\t\tWHERE licence_key = %s\n\t\t\t\tAND ( user_id = %d OR user_id = 0 )\n\t\t\t", $licence_key, get_current_user_id())); // Renewable? if (!$licence) { wc_add_notice(__('Invalid licence', 'wp-plugin-licencing'), 'error'); return; } if (!$licence->date_expires || strtotime($licence->date_expires) > current_time('timestamp')) { wc_add_notice(__('This licence does not need to be renewed yet', 'wp-plugin-licencing'), 'notice'); return; } // Purchasable? $product = get_product($licence->product_id); if (!$product->is_purchasable()) { wc_add_notice(__('This product can no longer be purchased', 'wp-plugin-licencing'), 'error'); return; } // Add to cart WC()->cart->empty_cart(); WC()->cart->add_to_cart($licence->product_id, 1, '', '', array('renewing_key' => $licence_key)); // Message wc_add_notice(sprintf(__('The product has been added to your cart with a %d%% discount.', 'wp-plugin-licencing'), apply_filters('wp_plugin_licencing_renewal_discount_percent', 30)), 'success'); // Redirect to checkout wp_redirect(get_permalink(wc_get_page_id('checkout'))); exit; } }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $config, $db, $plugin_config; $payment = $db->get_payment($payment_id); $member = $db->get_user($member_id); $product =& get_product($product_id); $this_config = $plugin_config['payment']['gate2shop']; if ($this_config['testing']) { // currently HTTP POST requests use version=3.0.0 while HTTP GET requests use version=1.0.0 $version = '1.0.0'; } else { $version = '3.0.0'; } $time_stamp = gmdate("Y-m-d.H:i:s"); // current GMT time in the following format: YYYY-MM-DD.HH:MM:SS $vars = array('version' => $version, 'merchant_id' => $this_config['merchant_id'], 'merchant_site_id' => $this_config['site_id'], 'currency' => $product->config['gate2shop_currency'] ? $product->config['gate2shop_currency'] : 'USD', 'numberofitems' => '1', 'item_name_1' => $product->config['title'], 'item_amount_1' => $product->config['price'], 'item_quantity_1' => 1, 'total_amount' => $price, 'time_stamp' => $time_stamp, 'total_tax' => $payment['data']['TAX_AMOUNT'], 'productId' => $product_id, 'merchantLocale' => 'en_US', 'userid' => $member['member_id'], 'first_name' => $member['name_f'], 'last_name' => $member['name_l'], 'address1' => $member['street'], 'city' => $member['city'], 'state' => $member['state'], 'country' => $member['country'], 'zip' => $member['zip'], 'email' => $member['email'], 'invoice_id' => $payment['payment_id'] . "-" . $this->get_rand(3), 'customField1' => $payment['payment_id'], 'customData' => $payment['payment_id']); $vars['checksum'] = md5($this_config['secret'] . $vars['merchant_id'] . $vars['currency'] . $vars['total_amount'] . $vars['item_name_1'] . $vars['item_amount_1'] . $vars['item_quantity_1'] . $vars['time_stamp']); if ($this_config['method'] == 'GET') { $this->encode_and_redirect('https://secure.Gate2Shop.com/ppp/purchase.do', $vars); exit; } else { $t =& new_smarty(); $t->assign('vars', $vars); $t->display(str_replace("c:\\", '/', dirname(__FILE__) . '/form.html')); exit; } }
/** * Checks if a given product is of a switchable type * * @param int|WC_Product $product A WC_Product object or the ID of a product to check * @return bool * @since 2.0 */ function wcs_is_product_switchable_type($product) { if (!is_object($product)) { $product = get_product($product); } if (empty($product)) { $is_product_switchable = false; } else { $allow_switching = get_option(WC_Subscriptions_Admin::$option_prefix . '_allow_switching', 'no'); switch ($allow_switching) { case 'variable': $is_product_switchable = $product->is_type(array('variable-subscription', 'subscription_variation')) ? true : false; break; case 'grouped': $is_product_switchable = 0 !== $product->post->post_parent ? true : false; break; case 'variable_grouped': $is_product_switchable = $product->is_type(array('variable-subscription', 'subscription_variation')) || 0 !== $product->post->post_parent ? true : false; break; case 'no': default: $is_product_switchable = false; break; } } return apply_filters('wcs_is_product_switchable', $is_product_switchable, $product); }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $config, $db; $products = $product_id; $orig_product_id = $product_id; if (is_array($product_id)) { $product_id = $product_id[0]; } $product =& get_product($product_id); if (count($orig_product_id) > 1) { $product->config['title'] = $config['multi_title']; } $member = $db->get_user($member_id); if (preg_match('/^\\d\\d\\d\\d-\\d\\d-\\d\\d$/', $product->config['start_date'])) { $begin_date = $product->config['start_date']; } else { $begin_date = date('Y-m-d'); } if (true || $product->config['is_recurring']) { // only subscriptions (for reason of Trials), if not recurring will use cycles == 1 $vars = array("_ipn_act" => "_ipn_subscription", "fid" => "", "itestmode" => $this->config['testmode'] ? "on" : "off", "notifyURL" => $config['root_url'] . "/plugins/payment/safepay/ipn.php", "returnURL" => sprintf("%s/thanks.php?member_id=%d&product_id=%d", $config['root_url'], $member_id, $product_id), "cancelURL" => $config['root_url'] . "/cancel.php", "notifyEml" => $this->config['notifyEml'], "iowner" => $this->config['owner'], "ireceiver" => $this->config['owner'], "iamount" => sprintf('%.2f', $price), "itemName" => $product->config['title'], "itemNum" => "1", "idescr" => $product->config['description'], "cycleLength" => $product->config['expire_days'] ? get_date_day_diff(time(), strtotime($product->get_expire($begin_date, 'expire_days'))) : '0', "cycles" => $product->config['is_recurring'] ? "0" : "1", "trialPeriod" => $product->config['trial1_days'] ? get_date_day_diff(time(), strtotime($product->get_expire($begin_date, 'trial1_days'))) : '0', "trialCycles" => "1", "trialAmount" => $product->config['trial1_price'], "idelivery" => "1", "iquantity" => "1", "imultiplyPurchase" => "n", "custom1" => $payment_id, "custom2" => "", "custom3" => "", "custom4" => "", "custom5" => "", "colortheme" => ""); } else { // DISABLED! (no Trials support here) $vars = array("_ipn_act" => "_ipn_payment", "fid" => "", "itestmode" => $this->config['testmode'] ? "on" : "off", "notifyURL" => $config['root_url'] . "/plugins/payment/safepay/ipn.php", "returnURL" => sprintf("%s/thanks.php?member_id=%d&product_id=%d", $config['root_url'], $member_id, $product_id), "cancelURL" => $config['root_url'] . "/cancel.php", "notifyEml" => $this->config['notifyEml'], "iowner" => $this->config['owner'], "ireceiver" => $this->config['owner'], "iamount" => sprintf('%.2f', $price), "itemName" => $product->config['title'], "itemNum" => "1", "idescr" => $product->config['description'], "idelivery" => "1", "iquantity" => "1", "imultiplyPurchase" => "n", "custom1" => $payment_id, "custom2" => "", "custom3" => "", "custom4" => "", "custom5" => "", "colortheme" => ""); } $vars1 = array(); foreach ($vars as $kk => $vv) { $v = urlencode($vv); $k = urlencode($kk); $vars1[] = "{$k}={$v}"; } $vars = join('&', $vars1); html_redirect("https://www.safepaysolutions.com/index.php?{$vars}", '', 'Please wait', 'Please wait'); exit; }
function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars) { global $config, $db; $products = $product_id; $orig_product_id = $product_id; if (is_array($product_id)) { $product_id = $product_id[0]; } $product =& get_product($product_id); if (count($orig_product_id) > 1) { $product->config['title'] = $config['multi_title']; } $member = $db->get_user($member_id); $vars = array('pay_to_email' => $this->config['business'], 'pay_from_email' => $member['email'], 'transaction_id' => $payment_id, 'return_url' => sprintf("%s/thanks.php?payment_id=%d", $config['root_url'], $payment_id), 'cancel_url' => $config['root_url'] . "/cancel.php", 'status_url' => $config['root_url'] . "/plugins/payment/moneybookers/ipn.php", 'amount' => sprintf('%.2f', $price), 'detail1_text' => $product->config['title'], 'firstname' => $member['name_f'], 'lastname' => $member['name_l'], 'address' => $member['street'], 'postal_code' => $member['zip'], 'city' => $member['city'], 'state' => $member['state'], 'country' => $member['country']); // add currency code if (strlen($product->config['moneybookers_currency'])) { $vars['currency'] = $product->config['moneybookers_currency']; } else { $vars['currency'] = 'USD'; } if ($product->config['is_recurring']) { unset($vars['amount']); $vars += array('rec_amount' => sprintf('%.2f', $price), 'rec_cycle' => "day", 'rec_period' => $this->get_days($product->config['expire_days'])); } $vars1 = array(); foreach ($vars as $kk => $vv) { $v = urlencode($vv); $k = urlencode($kk); $vars1[] = "{$k}={$v}"; } $vars = join('&', $vars1); header("Location: https://www.moneybookers.com/app/payment.pl?{$vars}"); exit; }
protected function getAllReviews() { global $wpdb; $query = "SELECT comment_post_ID AS product_id, \n\t\t\t\t\t\t comment_author AS display_name, \n\t\t\t\t\t\t comment_date AS date,\n\t\t\t\t\t\t comment_author_email AS user_email, \n\t\t\t\t\t\t comment_content AS review_content, \n\t\t\t\t\t\t meta_value AS review_score,\n\t\t\t\t\t\t post_content AS product_description,\n\t\t\t\t\t\t post_title AS product_title,\n\t\t\t\t\t\t user_id\n\t\t\t\t FROM `" . $wpdb->prefix . "comments` \n\t\t\t\t INNER JOIN `" . $wpdb->prefix . "posts` ON `" . $wpdb->prefix . "posts`.`ID` = `" . $wpdb->prefix . "comments`.`comment_post_ID` \n\t\t\t\t INNER JOIN `" . $wpdb->prefix . "commentmeta` ON `" . $wpdb->prefix . "commentmeta`.`comment_id` = `" . $wpdb->prefix . "comments`.`comment_ID` \n\t\t\t\t WHERE `post_type` = 'product' AND meta_key='rating'"; $results = $wpdb->get_results($query); $all_reviews = array(); foreach ($results as $value) { $product_instance = get_product($value->product_id); $current_review = array(); $review_content = $this->cleanContent($value->review_content); $current_review['review_title'] = $this->getFirstWords($review_content); $current_review['review_content'] = $review_content; $current_review['display_name'] = $this->cleanContent($value->display_name); $current_review['user_email'] = $value->user_email; $current_review['user_type'] = woocommerce_customer_bought_product($value->user_email, $value->user_id, $value->product_id) ? 'verified_buyer' : ''; $current_review['review_score'] = $value->review_score; $current_review['date'] = $value->date; $current_review['sku'] = $value->product_id; $current_review['product_title'] = $this->cleanContent($value->product_title); $current_review['product_description'] = $this->cleanContent($product_instance->get_post_data()->post_excerpt); $current_review['product_url'] = get_permalink($value->product_id); $current_review['product_image_url'] = wc_yotpo_get_product_image_url($value->product_id); $all_reviews[] = $current_review; } return $all_reviews; }
function custom_override_checkout_fields($fields) { global $woocommerce; $hasPhysicalProduct = false; if (!empty($woocommerce->cart->cart_contents)) { // Cart is not empty, now loop through the cart $cart = $woocommerce->cart->get_cart(); foreach ($cart as $key => $values) { $_product = get_product($values['variation_id'] ? $values['variation_id'] : $values['product_id']); if (!empty($_product) && $_product->exists() && $values['quantity'] > 0) { if ($_product->virtual == 'no' && $_product->downloadable == 'no') { $hasPhysicalProduct = true; } } } } if ($hasPhysicalProduct == false) { unset($fields['billing']['billing_address_1']); unset($fields['billing']['billing_address_2']); unset($fields['billing']['billing_company']); unset($fields['billing']['billing_city']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_country']); unset($fields['billing']['billing_state']); unset($fields['billing']['billing_phone']); } return $fields; }
public function wcva_register_my_scripts() { global $post, $product; if (!$post) { return; } $displaytypenumber = 0; $product = get_product($post->ID); if (is_product()) { $displaytypenumber = wcva_return_displaytype_number($product, $post); } wp_register_style('wcva-frontend', wcva_PLUGIN_URL . 'css/front-end.css'); $goahead = 1; if (isset($_SERVER['HTTP_USER_AGENT'])) { $agent = $_SERVER['HTTP_USER_AGENT']; } if (preg_match('/(?i)msie [5-8]/', $agent)) { $goahead = 0; } if ($displaytypenumber > 0 && $goahead == 1) { wp_deregister_script('wc-add-to-cart-variation'); wp_dequeue_script('wc-add-to-cart-variation'); wp_register_script('wc-add-to-cart-variation', wcva_PLUGIN_URL . 'js/manage-variation-selection.js', array('jquery'), false, true); } if (is_product()) { if ($displaytypenumber > 0 && $goahead == 1) { wp_enqueue_script('wc-add-to-cart-variation'); } wp_enqueue_style('wcva-frontend'); } }
public function get_all_image_ids($id) { $allImages = array(); $show_gallery = false; if (has_post_thumbnail($id)) { $allImages[] = get_post_thumbnail_id($id); } else { $prod = get_post($id); $prodParentId = $prod->post_parent; if ($prodParentId && has_post_thumbnail($prodParentId)) { $allImages[] = get_post_thumbnail_id($prodParentId); } else { $allImages[] = 'placeholder'; } $show_gallery = true; } if (get_post_type($id) == 'product_variation') { $wtAttachments = array_filter(explode(',', get_post_meta($id, '_wpb_variation_images', true))); $allImages = array_merge($allImages, $wtAttachments); } if (get_post_type($id) == 'product' || $show_gallery) { $product = get_product($id); $attachIds = $product->get_gallery_attachment_ids(); if (!empty($attachIds)) { $allImages = array_merge($allImages, $attachIds); } } return $allImages; }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { global $comments, $comment, $woocommerce; if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product')); if ($comments) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="product_list_widget">'; foreach ((array) $comments as $comment) { $_product = get_product($comment->comment_post_ID); $rating = intval(get_comment_meta($comment->comment_ID, 'rating', true)); $rating_html = $_product->get_rating_html($rating); echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">'; echo $_product->get_image(); echo $_product->get_title() . '</a>'; echo $rating_html; printf('<span class="reviewer">' . _x('by %1$s', 'by comment author', 'woocommerce') . '</span>', get_comment_author()); echo '</li>'; } echo '</ul>'; echo $after_widget; } $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
/** * Build the "Add to cart" HTML. * * @param string $url * @param string $stock_status * @param string $type * @return string * @static * @since 1.0.0 */ public static function add_to_cart_button($product_id, $stock_status) { global $yith_wcwl; if (function_exists('get_product')) { $product = get_product($product_id); } else { $product = new WC_Product($product_id); } $url = $product->product_type == 'external' ? $yith_wcwl->get_affiliate_product_url($product_id) : $yith_wcwl->get_addtocart_url($product_id); $label = $product->product_type == 'variable' ? apply_filters('variable_add_to_cart_text', __('Select options', 'yit')) : apply_filters('yith_wcwl_add_to_cart_label', get_option('yith_wcwl_add_to_cart_text')); $icon = get_option('yith_wcwl_use_button') == 'yes' && get_option('yith_wcwl_add_to_cart_icon') != 'none' ? '<i class="' . get_option('yith_wcwl_add_to_cart_icon') . '"></i>' : ''; $cartlink = ''; $redirect_to_cart = get_option('yith_wcwl_redirect_cart') == 'yes' && $product->product_type != 'variable' ? 'true' : 'false'; $style = ''; //indicates the style (background-color and font color) if (get_option('yith_wcwl_use_button') == 'yes') { if ($product->product_type == 'external') { $cartlink .= '<a target="_blank" class="add_to_cart button alt" href="' . $url . '"'; } else { $cartlink .= '<a class="add_to_cart button alt" onclick="check_for_stock(\'' . $url . '\',\'' . $stock_status . '\',\'' . $redirect_to_cart . '\');"'; } $cartlink .= $style . '>' . $icon . $label . '</a>'; } else { if ($product->product_type == 'external') { $cartlink .= '<a target="_blank" class="add_to_cart button alt" href="' . $url . '">' . $icon . $label . '</a>'; } else { $cartlink .= '<a class="add_to_cart button alt" href="javascript:void(0);" onclick="check_for_stock(\'' . $url . '\',\'' . $stock_status . '\',\'' . $redirect_to_cart . '\');">' . $icon . $label . '</a>'; } } return $cartlink; }
/** * column_default function. * * @access public * @param mixed $item * @param mixed $column_name */ function column_default($item, $column_name) { global $woocommerce, $wpdb, $product; if (!$product || $product->id !== $item->id) { $product = get_product($item->id); } switch ($column_name) { case 'product': if ($sku = $product->get_sku()) { echo $sku . ' - '; } echo $product->get_title(); // Get variation data if ($product->is_type('variation')) { $list_attributes = array(); $attributes = $product->get_variation_attributes(); foreach ($attributes as $name => $attribute) { $list_attributes[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': <strong>' . $attribute . '</strong>'; } echo '<div class="description">' . implode(', ', $list_attributes) . '</div>'; } break; case 'parent': if ($item->parent) { echo get_the_title($item->parent); } else { echo '-'; } break; case 'stock_status': if ($product->is_in_stock()) { echo '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>'; } else { echo '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>'; } break; case 'stock_level': echo $product->get_stock_quantity(); break; case 'wc_actions': ?> <p> <?php $actions = array(); $action_id = $product->is_type('variation') ? $item->parent : $item->id; $actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'woocommerce'), 'action' => "edit"); if ($product->is_visible()) { $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'woocommerce'), 'action' => "view"); } $actions = apply_filters('woocommerce_admin_stock_report_product_actions', $actions, $product); foreach ($actions as $action) { $image = isset($action['image_url']) ? $action['image_url'] : WC()->plugin_url() . '/assets/images/icons/' . $action['action'] . '.png'; printf('<a class="button tips" href="%s" data-tip="%s"><img src="%s" alt="%s" width="14" /></a>', esc_url($action['url']), esc_attr($action['name']), esc_attr($image), esc_attr($action['name'])); } ?> </p><?php break; } }
function wcms_get_product($product_id) { if (function_exists('get_product')) { return get_product($product_id); } else { return new WC_Product($product_id); } }
public function getProductObject($post_id) { // update cache if required if (!array_key_exists($post_id, $this->product_objects)) { $this->product_objects[$post_id] = get_product($post_id); } return $this->product_objects[$post_id]; }
/** * Get the WC Product instance for a given product ID or post * * get_product() is soft-deprecated in WC 2.2 * * @since 3.0.0 * @param bool|int|string|\WP_Post $the_product * @param array $args * @return WC_Product */ public static function wc_get_product($the_product = false, $args = array()) { if (self::is_wc_version_gte_2_2()) { return wc_get_product($the_product, $args); } else { return get_product($the_product, $args); } }
public function plugin_compatibility_filters() { if (is_product()) { if (!$this->user_can_purchase(get_product(get_the_ID()))) { add_filter('woocommerce_bv_render_form', '__return_false'); } } }
function do_bill($amount, $title, $products, $member, $invoice) { global $config, $db; $product =& get_product($products[0]['product_id']); $vars = array('SITE_ID' => $this->config['site_id'], 'PRICING_ID' => $product->config['zombaio_id'], 'LANG' => $this->config['lang'], 'FirstName' => $member['name_f'], 'LastName' => $member['name_l'], 'Address' => $member['street'], 'Postal' => $member['zip'], 'City' => $member['city'], 'Email' => $member['email'], 'Username' => $member['login'], 'Password' => $member['pass'], 'INVOICE' => $invoice); $t =& new_smarty(); $t->assign('vars', $vars); $t->display(dirname(__FILE__) . '/zombaio.html'); }
public function get_slider_items() { if (!defined('SCRIPT_DEBUG') || !SCRIPT_DEBUG) { @ini_set('display_errors', false); } global $wc_product_slider_a3_card_skin_card_layout_settings; $woocommerce_db_version = get_option('woocommerce_db_version', null); $slider_query_string = base64_decode($_REQUEST['slider_id']); $slider_settings = array(); if (isset($_REQUEST['slider_settings'])) { $slider_settings = $_REQUEST['slider_settings']; } $slider_data = array(); parse_str($slider_query_string, $slider_data); extract($slider_data); $product_results = $this->get_products_cat($category_id, $filter_type, 'title menu_order', $number_products, 0); $image_size = 'full'; $slider_items = array(); if (is_array($product_results) && count($product_results) > 0) { $index_product = 0; foreach ($product_results as $product) { $index_product++; $product_id = $product->ID; if (version_compare($woocommerce_db_version, '2.0', '<') && null !== $woocommerce_db_version) { $product_data = new WC_Product($product_id); } elseif (version_compare(WC()->version, '2.2.0', '<')) { $product_data = get_product($product_id); } else { $product_data = wc_get_product($product_id); } $product_price = $product_data->get_price_html(); $thumb_image_info = $this->get_image_info($product_id, $image_size); $thumb_image_url = $thumb_image_info['url']; $slide_data = array('item_title' => $product->post_title, 'item_link' => get_permalink($product_id), 'product_price' => $product_price, 'img_url' => $thumb_image_url, 'index_product' => $index_product); if (isset($slider_settings['skin_type'])) { switch ($slider_settings['skin_type']) { // For Mobile case 'mobile': $slide_data['is_used_mobile_skin'] = $slider_settings['is_used_mobile_skin']; $slide_data['category_link'] = $slider_settings['category_link']; $slide_data['tag_link'] = $slider_settings['tag_link']; break; // For Widget // For Widget default: if (isset($slider_data['widget_effect']) && $slider_data['widget_effect'] == 'random') { $slide_data['extra_attributes'] = WC_Product_Slider_Functions::get_transition_random($slider_settings); } break; } } $slider_items[] = $slide_data; } } header('Content-Type: application/json', true, 200); die(json_encode($slider_items)); }
/** * @since 1.0.0 of SA_WC_Compatibility_2_2 */ public static function get_product($the_product = false, $args = array()) { if (self::is_wc_gte_22()) { return wc_get_product($the_product, $args); } elseif (self::is_wc_21()) { return get_product($the_product, $args); } else { return new WC_Product($the_product); } }