1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 6 7 8 9 10 11 12 13 14 15
16 class WC_Product_Simple extends WC_Product {
17
18 19 20 21 22 23
24 public function __construct( $product ) {
25 $this->product_type = 'simple';
26 parent::__construct( $product );
27 }
28
29 30 31 32 33 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 43 44 45 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 55 56 57 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() ) . ' → ' . $title;
65 }
66
67 return apply_filters( 'woocommerce_product_title', $title, $this );
68 }
69
70 71 72 73 74 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 }