1 <?php
 2 
 3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 4 
 5 /**
 6  * Simple Product Class
 7  *
 8  * The default product type kinda product.
 9  *
10  * @class       WC_Product_Simple
11  * @version     2.0.0
12  * @package     WooCommerce/Classes/Products
13  * @category    Class
14  * @author      WooThemes
15  */
16 class WC_Product_Simple extends WC_Product {
17 
18     /**
19      * __construct function.
20      *
21      * @access public
22      * @param mixed $product
23      */
24     public function __construct( $product ) {
25         $this->product_type = 'simple';
26         parent::__construct( $product );
27     }
28 
29     /**
30      * Get the add to url used mainly in loops.
31      *
32      * @access public
33      * @return string
34      */
35     public function add_to_cart_url() {
36         $url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $this->id ) ) : get_permalink( $this->id );
37 
38         return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
39     }
40 
41     /**
42      * Get the add to cart button text
43      *
44      * @access public
45      * @return string
46      */
47     public function add_to_cart_text() {
48         $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read More', 'woocommerce' );
49 
50         return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
51     }
52 
53     /**
54      * Get the title of the post.
55      *
56      * @access public
57      * @return string
58      */
59     public function get_title() {
60 
61         $title = $this->post->post_title;
62 
63         if ( $this->get_parent() > 0 ) {
64             $title = get_the_title( $this->get_parent() ) . ' &rarr; ' . $title;
65         }
66 
67         return apply_filters( 'woocommerce_product_title', $title, $this );
68     }
69 
70     /**
71      * Sync grouped products with the children lowest price (so they can be sorted by price accurately).
72      *
73      * @access public
74      * @return void
75      */
76     public function grouped_product_sync() {
77         global $wpdb, $woocommerce;
78 
79         if ( ! $this->get_parent() ) return;
80 
81         $children_by_price = get_posts( array(
82             'post_parent'    => $this->get_parent(),
83             'orderby'        => 'meta_value_num',
84             'order'          => 'asc',
85             'meta_key'       => '_price',
86             'posts_per_page' => 1,
87             'post_type'      => 'product',
88             'fields'         => 'ids'
89         ));
90         if ( $children_by_price ) {
91             foreach ( $children_by_price as $child ) {
92                 $child_price = get_post_meta( $child, '_price', true );
93                 update_post_meta( $this->get_parent(), '_price', $child_price );
94             }
95         }
96 
97         wc_delete_product_transients( $this->id );
98     }
99 }
WooCommerce API documentation generated by ApiGen 2.8.0