The default product type kinda product.
저자: WooThemes
상속: extends WC_Product
예제 #1
0
 /**
  * Test product term setters and getters
  * @since 2.7.0
  */
 public function test_product_term_getters_and_setters()
 {
     $test_cat_1 = wp_insert_term('Testing 1', 'product_cat');
     $test_cat_2 = wp_insert_term('Testing 2', 'product_cat');
     $test_tag_1 = wp_insert_term('Tag 1', 'product_tag');
     $test_tag_2 = wp_insert_term('Tag 2', 'product_tag');
     $getters_and_setters = array('tag_ids' => array('Tag 1', 'Tag 2'), 'category_ids' => array($test_cat_1['term_id'], $test_cat_2['term_id']));
     $product = new WC_Product_Simple();
     foreach ($getters_and_setters as $function => $value) {
         $product->{"set_{$function}"}($value);
     }
     $product->save();
     $this->assertEquals(array($test_cat_1['term_id'], $test_cat_2['term_id']), $product->get_category_ids());
     $this->assertEquals(array($test_tag_1['term_id'], $test_tag_2['term_id']), $product->get_tag_ids());
 }
예제 #2
0
 /**
  * Construct.
  *
  * @access public
  * @param mixed $product
  */
 public function __construct($product)
 {
     parent::__construct($product);
     $this->product_type = 'tour';
     $this->virtual = 'yes';
     $this->downloadable = 'no';
 }
 /**
  * Checks if the store manager has requested the current product be limited to one purchase
  * per customer, and if so, checks whether the customer already has an active subscription to
  * the product.
  *
  * @access public
  * @return bool
  */
 function is_purchasable()
 {
     $purchasable = parent::is_purchasable();
     if (true === $purchasable && 'yes' == $this->limit_subscriptions) {
         if (WC_Subscriptions_Manager::user_has_subscription(0, $this->id, 'active')) {
             $purchasable = false;
         }
     }
     return apply_filters('woocommerce_subscription_is_purchasable', $purchasable, $this);
 }
 /**
  * Checks if the store manager has requested the current product be limited to one purchase
  * per customer, and if so, checks whether the customer already has an active subscription to
  * the product.
  *
  * @access public
  * @return bool
  */
 function is_purchasable()
 {
     $purchasable = parent::is_purchasable();
     if (true === $purchasable && false === WC_Subscriptions_Product::is_purchasable($purchasable, $this)) {
         $purchasable = false;
     }
     return apply_filters('woocommerce_subscription_is_purchasable', $purchasable, $this);
 }
 /**
  * Checks if the store manager has requested the current product be limited to one purchase
  * per customer, and if so, checks whether the customer already has an active subscription to
  * the product.
  *
  * @access public
  * @return bool
  */
 function is_purchasable()
 {
     $purchasable = parent::is_purchasable();
     if (true === $purchasable && 'no' != $this->limit_subscriptions && is_user_logged_in() && ('active' == $this->limit_subscriptions && WC_Subscriptions_Manager::user_has_subscription(0, $this->id, 'on-hold') || WC_Subscriptions_Manager::user_has_subscription(0, $this->id, $this->limit_subscriptions)) && false === strpos($_SERVER['REQUEST_URI'], 'order-received')) {
         // we can't use is_order_received_page() becuase get_cart_from_session() is called before the query vars are setup
         $purchasable = false;
     }
     return apply_filters('woocommerce_subscription_is_purchasable', $purchasable, $this);
 }
 /**
  * Returns false if the product cannot be bought.
  * Override abstract method so that: i) Disabled variations are not be purchasable by admins. ii) Enabled variations are not purchasable if the parent product is not purchasable.
  *
  * @return bool
  */
 public function is_purchasable()
 {
     return apply_filters('woocommerce_variation_is_purchasable', $this->variation_is_visible() && parent::is_purchasable(), $this);
 }
 public static function order_status_changed($id, $status = '', $new_status = '')
 {
     $rules = get_option('woorule_rules', array());
     foreach ($rules as $k => $rule) {
         $enabled = get_option($rule['enabled']['id']) === 'yes' ? true : false;
         if ($enabled) {
             $which_event = get_option($rule['occurs']['id']);
             $is_opt_in_rule = false;
             $want_in = true;
             if (isset($rule['show_opt_in'])) {
                 $is_opt_in_rule = get_option($rule['show_opt_in']['id']) === 'yes' ? true : false;
             }
             if ($is_opt_in_rule) {
                 $want_in = get_post_meta($id, 'woorule_opt_in_' . $k, false);
                 if (!empty($want_in)) {
                     $want_in = $want_in[0] === 'yes' ? true : false;
                 }
             }
             if ($want_in && $new_status === $which_event) {
                 $integration = new WC_Integration_RuleMailer();
                 $order = new WC_Order($id);
                 $user = $order->get_user();
                 $currency = $order->get_order_currency();
                 $order_subtotal = $order->order_total - ($order->order_shipping_tax + $order->order_shipping) - $order->cart_discount;
                 $items = $order->get_items();
                 $brands = array();
                 $categories = array();
                 $tags = array();
                 foreach ($items as $item) {
                     $p = new WC_Product_Simple($item['product_id']);
                     $brands[] = $p->get_attribute('brand');
                     // this is bullshit
                     $cat = strip_tags($p->get_categories(''));
                     $tag = strip_tags($p->get_tags(''));
                     if (!empty($cat)) {
                         $categories[] = $cat;
                     }
                     if (!empty($tag)) {
                         $tags[] = $tag;
                     }
                 }
                 $subscription = array('apikey' => $integration->api_key, 'update_on_duplicate' => get_option($rule['update_on_duplicate']['id']) === 'yes' ? true : false, 'auto_create_tags' => get_option($rule['auto_create_tags']['id']) === 'yes' ? true : false, 'auto_create_fields' => get_option($rule['auto_create_fields']['id']) === 'yes' ? true : false, 'tags' => explode(',', get_option($rule['tags']['id'])), 'subscribers' => array('email' => $order->billing_email, 'phone_number' => $order->billing_phone, 'fields' => array(array('key' => 'Order.Number', 'value' => $order->get_order_number()), array('key' => 'Order.Date', 'value' => $order->order_date), array('key' => 'Order.FirstName', 'value' => $order->billing_first_name), array('key' => 'Order.LastName', 'value' => $order->billing_last_name), array('key' => 'Order.Street1', 'value' => $order->billing_address_1), array('key' => 'Order.Street2', 'value' => $order->billing_address_2), array('key' => 'Order.City', 'value' => $order->billing_city), array('key' => 'Order.Country', 'value' => $order->billing_country), array('key' => 'Order.State', 'value' => $order->billing_state), array('key' => 'Order.Subtotal', 'value' => $order_subtotal), array('key' => 'Order.Discount', 'value' => $order->cart_discount), array('key' => 'Order.Shipping', 'value' => $order->order_shipping + $order->order_shipping_tax), array('key' => 'Order.Total', 'value' => $order->order_total), array('key' => 'Order.Vat', 'value' => $order->order_tax))));
                 if (!empty($categories)) {
                     $subscription['subscribers']['fields'][] = array('key' => 'Order.Categories', 'value' => $categories, 'type' => 'multiple');
                 }
                 if (!empty($tags)) {
                     $subscription['subscribers']['fields'][] = array('key' => 'Order.Tags', 'value' => array($tags), 'type' => 'multiple');
                 }
                 if (!empty($brands)) {
                     $subscription['subscribers']['fields'][] = array('key' => 'Order.Brands', 'value' => $brands, 'type' => 'multiple');
                 }
                 $api = WP_RuleMailer_API::get_instance();
                 $api::subscribe($integration->api_url, $subscription);
             }
         }
     }
 }
<?php

global $post;
$args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'id', 'order' => 'asc', 'post_parent' => $post->ID);
$levels = get_posts($args);
do_action('woocommerce_before_add_to_cart_button');
?>
<div class="sp-widget-levels">
	<div class="sp-widget-levels">
		<?php 
foreach ($levels as $level) {
    $level_product = new WC_Product_Simple($level->ID);
    $level_data = get_post_custom($level->ID);
    ?>
			<form id="level-<?php 
    echo $level->ID;
    ?>
-form" enctype="multipart/form-data" method="post" class="cart" action="<?php 
    echo $level_product->add_to_cart_url();
    ?>
">
				<a class="sp-widget-level" rel="<?php 
    echo $level->ID;
    ?>
">
					<div class="sp-widget-level-title">
						<?php 
    echo get_the_title($level->ID);
    ?>
						<div class="sp-level-amount">
							<strong>$<?php 
 function __construct($product)
 {
     parent::__construct($product);
     $this->product_type = 'donation';
 }
예제 #10
0
 /**
  * Test wc_update_product_stock().
  *
  * @since 2.3
  */
 public function test_wc_update_product_stock()
 {
     // Create product
     $product = WC_Helper_Product::create_simple_product();
     update_post_meta($product->get_id(), '_manage_stock', 'yes');
     wc_update_product_stock($product->get_id(), 5);
     $product = new WC_Product_Simple($product->get_id());
     $this->assertEquals(5, $product->get_stock_quantity());
     // Delete Product
     WC_Helper_Product::delete_product($product->get_id());
 }
 /**
  *
  */
 public function get_bundle_price($price, $values)
 {
     // set starting price
     $price = 0;
     // go through each item
     foreach ($values['stamp'] as $item) {
         // determine the type, create new object for each, then get its price
         switch ($item['type']) {
             case 'variable':
                 $prod = new WC_Product_Variation($item['product_id']);
                 $p_price = $prod->get_price();
                 break;
             default:
                 // simple
                 $prod = new WC_Product_Simple($item['product_id']);
                 $p_price = $prod->get_price();
                 break;
         }
         // if there is a discount
         if ($item['discount'] != 0) {
             // subtract the discount from the price
             $p_price = $p_price - $item['discount'] / 100 * $p_price;
         }
         // add the item's price to the total
         $price = $price + $p_price * $item['quantity'];
     }
     // format and return
     return number_format($price, 2);
 }