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); }
/** * Test product setters and getters * @since 2.7.0 */ public function test_product_getters_and_setters() { global $wpdb; $attributes = array(); $attribute = new WC_Product_Attribute(); $attribute->set_id(0); $attribute->set_name('Test Attribute'); $attribute->set_options(array('Fish', 'Fingers')); $attribute->set_position(0); $attribute->set_visible(true); $attribute->set_variation(false); $attributes['test-attribute'] = $attribute; $getters_and_setters = array('name' => 'Test', 'slug' => 'test', 'status' => 'publish', 'catalog_visibility' => 'search', 'featured' => false, 'description' => 'Hello world', 'short_description' => 'hello', 'sku' => 'TEST SKU', 'regular_price' => 15.0, 'sale_price' => 10.0, 'date_on_sale_from' => '1475798400', 'date_on_sale_to' => '1477267200', 'total_sales' => 20, 'tax_status' => 'none', 'tax_class' => '', 'manage_stock' => true, 'stock_quantity' => 10, 'stock_status' => 'instock', 'backorders' => 'notify', 'sold_individually' => false, 'weight' => 100, 'length' => 10, 'width' => 10, 'height' => 10, 'upsell_ids' => array(2, 3), 'cross_sell_ids' => array(4, 5), 'parent_id' => 0, 'reviews_allowed' => true, 'default_attributes' => array(), 'purchase_note' => 'A note', 'menu_order' => 2, 'gallery_image_ids' => array(), 'download_expiry' => -1, 'download_limit' => 5, 'attributes' => $attributes); $product = new WC_Product(); foreach ($getters_and_setters as $function => $value) { $product->{"set_{$function}"}($value); } $product->save(); $product = new WC_Product_Simple($product->get_id()); foreach ($getters_and_setters as $function => $value) { $this->assertEquals($value, $product->{"get_{$function}"}(), $function); } $image_url = media_sideload_image("https://cldup.com/Dr1Bczxq4q.png", $product->get_id(), '', 'src'); $image_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $image_url)); $product->set_image_id($image_id[0]); $product->save(); $this->assertEquals($image_id[0], $product->get_image_id()); }
/** * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting. * Should be safe to remove when we drop WC 2.2 compatibility * * @param WC_Product $product the product object * @param string $price to calculate, left blank to just use get_price() * @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax() * @return string */ public static function get_product_display_price($product, $price = '', $qty = 1) { if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) { return $product->get_display_price($price, $qty); } else { if ($price === '') { $price = $product->get_price(); } $tax_display_mode = get_option('woocommerce_tax_display_shop'); $display_price = $tax_display_mode == 'incl' ? $product->get_price_including_tax($qty, $price) : $product->get_price_excluding_tax($qty, $price); return $display_price; } }
/** * Replaces variation SKUs with the parent SKU * * @param array $line_item the line item's data in the export * @param array $item the order item being exported * @param \WC_Product $product the product associated with the item * @return array - updated line item */ function sv_wc_csv_export_order_line_item_sku($line_item, $item, $product) { if ($product->is_type('variation')) { $line_item['sku'] = $product->parent->get_sku(); } return $line_item; }
/** * Filter the document table row cells to add product thumbnail column data * * @param string $table_row_cells The table row cells. * @param string $type WC_PIP_Document type * @param string $item_id Item id * @param array $item Item data * @param \WC_Product $product Product object * @return array The filtered table row cells. */ function sv_wc_pip_document_table_row_cells_product_thumbnail($table_row_cells, $document_type, $item_id, $item, $product) { // get the product's or variation's thumbnail 'shop_thumbnail' size; we will use CSS to set the width $thumbnail_content = array('product_thumbnail' => $product->get_image()); // add product thumnail column as the first column return array_merge($thumbnail_content, $table_row_cells); }
/** * Handle redirects before content is output - hooked into template_redirect so is_page works **/ function woocommerce_redirects() { global $woocommerce, $wp_query; // When default permalinks are enabled, redirect shop page to post type archive url if (isset($_GET['page_id']) && $_GET['page_id'] > 0 && get_option('permalink_structure') == "" && $_GET['page_id'] == woocommerce_get_page_id('shop')) { wp_safe_redirect(get_post_type_archive_link('product')); exit; } // When on the checkout with an empty cart, redirect to cart page if (is_page(woocommerce_get_page_id('checkout')) && sizeof($woocommerce->cart->get_cart()) == 0) { wp_redirect(get_permalink(woocommerce_get_page_id('cart'))); exit; } // When on pay page with no query string, redirect to checkout if (is_page(woocommerce_get_page_id('pay')) && !isset($_GET['order'])) { wp_redirect(get_permalink(woocommerce_get_page_id('checkout'))); exit; } // My account page redirects (logged out) if (!is_user_logged_in() && (is_page(woocommerce_get_page_id('edit_address')) || is_page(woocommerce_get_page_id('view_order')) || is_page(woocommerce_get_page_id('change_password')))) { wp_redirect(get_permalink(woocommerce_get_page_id('myaccount'))); exit; } // Redirect to the product page if we have a single product if (is_search() && is_post_type_archive('product') && get_option('woocommerce_redirect_on_single_search_result') == 'yes') { if ($wp_query->post_count == 1) { $product = new WC_Product($wp_query->post->ID); if ($product->is_visible()) { wp_safe_redirect(get_permalink($product->id), 302); } exit; } } }
function ss_upsells_display( $product ){ $settings = get_option ( 'shopstyler' ); $product = new WC_Product( get_the_ID() ); $upsells = $product->get_upsells(); if (!$upsells) return; $meta_query = WC()->query->get_meta_query(); $args = array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => $settings['woo_upsell_limit'], 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $upsells, 'post__not_in' => array($product->id), 'meta_query' => $meta_query ); $wp_query = new WP_Query($args); if ( $wp_query->have_posts() ){ ss_render_query ( $wp_query , $settings['woo_upsell_label'] ); } }
/** * Validate Klarna order * Checks order items' stock status. * * @since 1.0.0 */ public static function validate_checkout_listener() { // Read the post body $post_body = file_get_contents('php://input'); // Convert post body into native object $data = json_decode($post_body, true); $all_in_stock = true; if (get_option('woocommerce_manage_stock') == 'yes') { $cart_items = $data['cart']['items']; foreach ($cart_items as $cart_item) { if ('physical' == $cart_item['type']) { $cart_item_product = new WC_Product($cart_item['reference']); if (!$cart_item_product->has_enough_stock($cart_item['quantity'])) { $all_in_stock = false; } } } } if ($all_in_stock) { header('HTTP/1.0 200 OK'); } else { header('HTTP/1.0 303 See Other'); header('Location: ' . WC()->cart->get_cart_url()); } }
/** * Backports WC_Product::get_id() method to 2.4.x * * @link https://github.com/woothemes/woocommerce/pull/9765 * * @since 4.2.0 * @param \WC_Product $product product object * @return string|int product ID */ public static function product_get_id(WC_Product $product) { if (self::is_wc_version_gte_2_5()) { return $product->get_id(); } else { return $product->is_type('variation') ? $product->variation_id : $product->id; } }
/** * Checks a given product to determine if it is a subscription. * * Can be passed either a product object or product ID. * * @since 1.0 */ public static function is_subscription($product) { if (!is_object($product)) { $product = new WC_Product($product); } // Shouldn't matter if product is variation as all we need is the product_type return $product->is_type(WC_Subscriptions::$name) ? true : false; }
protected function get_name(WC_Product $product) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . (isset($product->variation_id) ? $product->variation_id : $product->id); } return sprintf('%s - %s', $identifier, $product->get_title()); }
public function ajax_get_products_per_period() { $product_num = isset($_POST['product_num']) ? $_POST['product_num'] : 10; $start_date = isset($_POST['start_date']) ? $_POST['start_date'] : null; $end_date = isset($_POST['end_date']) ? $_POST['end_date'] : null; $results = []; $stats = $this->get_products_per_period(100, $start_date, $end_date); //wcds_var_dump($stats); /*Format: array(4) { [0]=> array(4) { ["total_earning"]=> string(1) "4" ["total_purchases"]=> string(1) "4" ["prod_id"]=> string(2) "12" ["prod_variation_id"]=> string(1) "0" } */ $counter = 0; $wpml_helper = new WCDS_Wpml(); foreach ($stats as $prod_id => $product) { //WPML: Merge product stats by id $stats[$prod_id]['total_earning'] = round($product['total_earning'], 2); $stats[$prod_id]['permalink'] = get_permalink($prod_id); if ($wpml_helper->wpml_is_active()) { $original_id = $wpml_helper->get_original_id($prod_id); $product_temp = new WC_Product($original_id); $stats[$prod_id]['prod_title'] = $product_temp->get_title(); $stats[$prod_id]['permalink'] = get_permalink($original_id); //wcds_var_dump($prod_id." -> ".$original_id); if (!isset($results[$original_id])) { //wcds_var_dump("new"); $results[$original_id] = $stats[$prod_id]; } else { //wcds_var_dump("update"); $results[$original_id]["total_earning"] += $product["total_purchases"]; $results[$original_id]["total_earning"] += $product["total_earning"]; $results[$original_id]["total_earning"] = round($results[$original_id]['total_earning'], 2); } } else { $results[$prod_id] = $stats[$prod_id]; } if (++$counter == $product_num) { break; } } usort($results, function ($a, $b) { return $b['total_earning'] - $a['total_earning']; }); echo json_encode($results); wp_die(); }
/** * Add the product id & variation ID to the individual line item entry * * @param array $line_item the original line item data * @param array $item WC order item data * @param WC_Product $product the product * @return array $line_item the updated line item data */ function sv_wc_csv_export_order_line_item_id($line_item, $item, $product) { $line_item['item_id'] = $product->id; $line_item['variation_id'] = ''; // set the variation id for variable products if ($product->is_type('variation')) { $line_item['variation_id'] = $product->get_variation_id(); } return $line_item; }
/** * Build the line items hash * @param array $items */ function build_line_items($items) { $line_items = array(); foreach ($items as $item) { $productmeta = new WC_Product($item['product_id']); $sku = $productmeta->get_sku(); $line_items = array_merge($line_items, array(array('name' => $item['name'], 'unit_price' => floatval($item['line_total']) * 100, 'description' => $item['name'], 'quantity' => $item['qty'], 'sku' => $sku, 'type' => $item['type']))); } return $line_items; }
/** * Test updating a product. * * @since 2.7.0 */ function test_product_update() { $product = WC_Helper_Product::create_simple_product(); $this->assertEquals('10', $product->get_regular_price()); $product->set_regular_price(15); $product->save(); // Reread from database $product = new WC_Product($product->get_id()); $this->assertEquals('15', $product->get_regular_price()); }
/** * Add the product price to the individual line item entry * * @param array $line_item the original line item data * @param array $item WC order item data * @param WC_Product $product the product * @return array updated line item data */ function sv_wc_csv_export_order_line_item_price($line_item, $item, $product) { $new_line_item = array(); foreach ($line_item as $key => $data) { $new_line_item[$key] = $data; // add this in the JSON / pipe-format after the SKU if ('sku' === $key) { $new_line_item['price'] = wc_format_decimal($product->get_price(), 2); } } return $new_line_item; }
function woocommerce_gravityforms_get_updated_price() { global $woocommerce; header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); $variation_id = isset($_POST['variation_id']) ? $_POST['variation_id'] : ''; $product_id = isset($_POST['product_id']) ? $_POST['product_id'] : 0; $gform_total = isset($_POST['gform_total']) ? $_POST['gform_total'] : 0; $product_data = null; if (function_exists('get_product')) { $product_data = get_product($variation_id > 0 ? $variation_id : $product_id); } else { if ($variation_id > 0) { $product_data = new WC_Product_Variation($variation_id); } else { $product_data = new WC_Product($product_id); } } $discount_price = false; $gforms_discount_price = false; $base_price = $product_data->get_price(); if (class_exists('WC_Dynamic_Pricing')) { $working_price = $base_price; $dynamic_pricing = WC_Dynamic_Pricing::instance(); foreach ($dynamic_pricing->modules as $module) { if ($module->module_type == 'simple') { //Make sure we are using the price that was just discounted. $working_price = $discount_price ? $discount_price : $base_price; $working_price = $module->get_product_working_price($working_price, $product_data); if (floatval($working_price)) { $discount_price = $module->get_discounted_price_for_shop($product_data, $working_price); } } } $gforms_base_price = $base_price + $gform_total; $gforms_working_price = $base_price + $gform_total; foreach ($dynamic_pricing->modules as $module) { if ($module->module_type == 'simple') { //Make sure we are using the price that was just discounted. $gforms_working_price = $gforms_discount_price ? $gforms_discount_price : $gforms_base_price; $gforms_working_price = $module->get_product_working_price($gforms_working_price, $product_data); if (floatval($gforms_working_price)) { $gforms_discount_price = $module->get_discounted_price_for_shop($product_data, $gforms_working_price); } } } } $price = $discount_price ? $discount_price : $base_price; $gform_final_total = $gforms_discount_price ? $gforms_discount_price : $price + $gform_total; $result = array('formattedBasePrice' => apply_filters('woocommerce_gform_base_price', woocommerce_price($price), $product_data), 'formattedTotalPrice' => apply_filters('woocommerce_gform_total_price', woocommerce_price($gform_final_total), $product_data), 'formattedVariationTotal' => apply_filters('woocommerce_gform_variation_total_price', woocommerce_price($gform_total), $product_data)); echo json_encode($result); die; }
public function get_base_product_price($id, $price) { if (!defined('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING')) { define('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING', true); } $product = new WC_Product($id); if ($price == 'product_regular_price') { return $product->get_regular_price(); } if ($price == 'product_selling_price') { return $product->get_sale_price(); } }
/** * Sync grouped product prices with children. * * @since 2.7.0 * @param WC_Product|int $product */ public function sync_price(&$product) { global $wpdb; $children_ids = get_posts(array('post_parent' => $product->get_id(), 'post_type' => 'product', 'fields' => 'ids')); $prices = $children_ids ? array_unique($wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_price' AND post_id IN ( " . implode(',', array_map('absint', $children_ids)) . " )")) : array(); delete_post_meta($product->get_id(), '_price'); delete_transient('wc_var_prices_' . $product->get_id()); if ($prices) { sort($prices); // To allow sorting and filtering by multiple values, we have no choice but to store child prices in this manner. foreach ($prices as $price) { add_post_meta($product->get_id(), '_price', $price, false); } } }
/** * Set stock level of the product. * * @param mixed $amount (default: null) * @param string $mode can be set, add, or subtract * @return int Stock */ function set_stock($amount = null, $mode = 'set') { // Empty total stock so its refreshed $this->total_stock = ''; // Call parent set_stock return parent::set_stock($amount, $mode); }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { global $comments, $comment, $woocommerce; $cache = wp_cache_get('widget_recent_reviews', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Reviews', 'woocommerce') : $instance['title'], $instance, $this->id_base); if (!($number = absint($instance['number']))) { $number = 5; } $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 = new WC_Product($comment->comment_post_ID); $star_size = apply_filters('woocommerce_star_rating_size_recent_reviews', 16); $rating = get_comment_meta($comment->comment_ID, 'rating', true); $rating_html = '<div class="star-rating" title="' . $rating . '"> <span style="width:' . $rating * $star_size . 'px">' . $rating . ' ' . __('out of 5', 'woocommerce') . '</span> </div>'; 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(_x('by %1$s', 'by comment author', 'woocommerce'), get_comment_author()) . '</li>'; } echo '</ul>'; echo $after_widget; } $content = ob_get_clean(); if (isset($args['widget_id'])) { $cache[$args['widget_id']] = $content; } echo $content; wp_cache_set('widget_recent_reviews', $cache, 'widget'); }
/** * Add woo attributes to a custom field with the same name * * @param $custom_fields * @param $post_id * * @return mixed */ public function filter_custom_fields($custom_fields, $post_id) { if (!isset($custom_fields)) { $custom_fields = array(); } // Get the product correponding to this post $product = new WC_Product($post_id); foreach ($product->get_attributes() as $attribute) { //$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) ); // Remove the eventual 'pa_' prefix from the attribute name $attribute_name = $attribute['name']; if (substr($attribute_name, 0, 3) == 'pa_') { $attribute_name = substr($attribute_name, 3, strlen($attribute_name)); } $custom_fields[$attribute_name] = explode(',', $product->get_attribute($attribute['name'])); } return $custom_fields; }
/** * Listens to see if an item is added to the cart. If it is, * this will check to see if the item is a ipad enclosure. * If the item is an ipad enclosure it will then add a filter * telling the customer to pick up an ipad enclosure * * @param id Product ID used to instantiate a product */ function jm_add_to_cart_listener($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) { // Fetch a product object using the product id $product = new WC_Product($product_id); // Get all of the product categories this item belongs too $terms = wp_get_post_terms($product->get_post_data()->ID, 'product_cat'); // Add all the categories to an array foreach ($terms as $term) { $categories[] = $term->slug; } // If the array contains ipad-enclosures we know this was indeed a mount if (in_array('ipad-enclosures', $categories)) { add_filter('woocommerce_add_to_cart_message', 'jm_add_to_cart_ipad_enclosure', 999); } // If the array contains ipad-enclosures we know this was indeed a enclosure if (in_array('ipad-mounts', $categories)) { add_filter('woocommerce_add_to_cart_message', 'jm_add_to_cart_ipad_mount', 999); } }
/** * __construct function. * * @access public * @param mixed $product * */ public function __construct($product) { global $sitepress; date_default_timezone_set("UTC"); $this->product_type = 'auction'; $this->auction_item_condition_array = apply_filters('simple_auction_item_condition', array('new' => __('New', 'wc_simple_auctions'), 'used' => __('Used', 'wc_simple_auctions'))); parent::__construct($product); $this->is_closed(); $this->is_started(); }
public function get_related_products($product_item, $intro) { $posts_per_page = $intro->get_posts_per_page(); $product = new WC_Product($product_item); $related = $product->get_related($posts_per_page); if (sizeof($related) == 0) { return; } $args = apply_filters("woocommerce_related_products_args", array("post_type" => "product", "ignore_sticky_posts" => 1, "no_found_rows" => 1, "posts_per_page" => $posts_per_page, "orderby" => get_option("woocommerce_default_catalog_orderby"), "post__in" => $related, "post__not_in" => array($product_item->post->ID))); $loop = new WP_Query($args); $prods = array(); while ($loop->have_posts()) { $loop->the_post(); global $product; $prod = $this->get_product_query($intro, array(product_name => $product->post->post_name)); array_push($prods, new JSON_API_Product_Model($prod)); } $intro->set_value($this, "related", $prods); }
/** Modified Function - create matrix for row -- 03/02/2016 **/ function woocommerce_bulk_variations_create_matrix_v24($post_id) { // 2.0 Compat if (function_exists('get_product')) { $_product = get_product($post_id); } else { $_product = new WC_Product($post_id); } $attributes = $_product->get_attributes(); //Get first attribute -- 03/02/2016 if (is_array($attributes) && count($attributes) > 0) { foreach ($attributes as $att) { $row_attribute = $att['name']; break; } } $av_temp = $_product->get_variation_attributes(); $av = array(); if (isset($attributes[$row_attribute]) && $attributes[$row_attribute]['is_taxonomy']) { $row_term_values = WC_Bulk_Variations_Compatibility::wc_get_product_terms($post_id, $row_attribute, 'all'); foreach ($row_term_values as $row_term_value) { if (in_array($row_term_value->slug, $av_temp[$row_attribute])) { $av[$row_attribute][] = $row_term_value->slug; } } } else { $av[$row_attribute] = $av_temp[$row_attribute]; } $grid = array(); foreach ($av[$row_attribute] as $row_value) { $grid[$row_value] = null; } //Now sanitize the attributes, since $product->get_available_variations returns the variations sanitized, but get_variation_attributes does not $row_attribute = sanitize_title($row_attribute); $pv = $_product->get_available_variations(); $filter = new WC_Bulk_Variation_Array_Filter('attribute_' . $row_attribute, $pv); foreach ($grid as $row_key => &$field_value) { $field_value = $filter->get_matches($row_key); } $matrix_data = array('row_attribute' => $row_attribute, 'matrix_rows' => array_values($av[$row_attribute]), 'matrix' => $grid); return $matrix_data; }
/** * __construct function. * * @access public * @param mixed $product */ public function __construct($product = array()) { $this->virtual = 'yes'; $this->downloadable = 'yes'; $this->manage_stock = 'yes'; $this->product_type = 'ticket'; add_filter('woocommerce_product_data_tabs', array($this, 'remove_tabs'), 10, 1); add_filter('product_type_options', array($this, 'add_virtual'), 10, 1); $getdir = ''; parent::__construct($product); }
/** * Pluggable function to render the frontend product page voucher fields * * @since 1.2 * @param WC_Product $product the voucher product */ function wc_pdf_product_vouchers_render_product_voucher_fields($product) { if ($product->is_type('variable')) { foreach ($product->get_children() as $variation_product_id) { $products[] = wc_get_product($variation_product_id); } } else { $products[] = $product; } foreach ($products as $product) { $voucher = WC_PDF_Product_Vouchers_Product::get_voucher($product); if ($voucher) { $fields = $voucher->get_user_input_voucher_fields(); $images = $voucher->get_image_urls(); if ($fields || $images) { // load the template file wc_get_template('single-product/product-voucher.php', array('product' => $product, 'product_id' => isset($product->variation_id) ? $product->variation_id : $product->id, 'voucher' => $voucher, 'fields' => $fields, 'images' => $images), '', wc_pdf_product_vouchers()->get_plugin_path() . '/templates/'); } } } }
function export_products() { $api_key = get_option('pixelshop_key'); $path = apply_filters('pixelshop/get_info', 'path'); include_once $path . 'core/api.php'; if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'export_products') && $api_key !== false) { $api = new API($api_key); $args = array('post_type' => 'product', 'orderby' => $orderby, 'post_status' => 'publish', 'posts_per_page' => -1); $the_query = new WP_Query($args); $products = []; $i = 0; while ($the_query->have_posts()) { $i++; $the_query->the_post(); $product = new WC_Product($the_query->post->ID); $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($the_query->post->ID), array(250, 250)); $products[$i] = ["sync_id" => $the_query->post->ID, "link" => get_permalink($the_query->post->ID), "title" => get_the_title(), "description" => get_the_excerpt(), "price" => $product->get_price(), "sku" => $product->get_sku(), "thumb" => $thumb[0], "tags" => '']; if (!isset($product->get_tags()->errors)) { $tags = wp_get_object_terms($the_query->post->ID, 'product_tag'); $tags_list = ''; foreach ($tags as $tag) { $tags_list .= $tag->name . ', '; } $products[$i]["tags"] = substr($tags_list, 0, -2); } } $export = $api->export->products($products); if (isset($export['error'])) { add_action('admin_notices', array($this, 'api_key_invalid')); } else { add_option('pixelshop_message', $export, '', 'yes'); $time = 60 * 60 * 24; if (get_option('pxs_last_export') === false) { add_option('pxs_last_export', time() + $time, '', 'no'); } else { update_option('pxs_last_export', time() + $time); } } } }
/** * __construct function. * * @access public * @param mixed $product */ public function __construct($product) { $this->product_type = 'amazon_listing'; $this->id = 0; $this->asin = $product; $this->sku = $product; // this will show the ASIN on the generated email $this->post = new stdClass(); // prevent non-object warning in /woocommerce/includes/abstracts/abstract-wc-product.php:693 $this->post->post_status = 'publish'; // make product purchasable for WooCommerce (?) parent::__construct($product); // parent::__construct( 0 ); }