| 1 |
<?php |
| 2 |
|
| 3 |
class Coupon_Code extends Tag_Base { |
| 4 |
/** |
| 5 |
* Get class id. |
| 6 |
* |
| 7 |
* @return string |
| 8 |
*/ |
| 9 |
public function get_id() { |
| 10 |
return '_coupon_code'; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Get class title. |
| 15 |
* |
| 16 |
* @return string |
| 17 |
*/ |
| 18 |
public function get_title() { |
| 19 |
return esc_html__( 'Coupon Code', 'sellkit' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Render true content. |
| 24 |
* |
| 25 |
* @param array $atts array of shortcode arguments. |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public function render_content( $atts ) { |
| 29 |
$this->get_data(); |
| 30 |
|
| 31 |
if ( empty( self::$order ) ) { |
| 32 |
return $this->shortcode_content( $atts ); |
| 33 |
} |
| 34 |
|
| 35 |
$order_data = $this->get_coupon_data( self::$order ); |
| 36 |
|
| 37 |
if ( empty( $order_data ) ) { |
| 38 |
return $this->shortcode_content( $atts ); |
| 39 |
} |
| 40 |
|
| 41 |
return $order_data; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get coupon data. |
| 46 |
* |
| 47 |
* @since 1.2.2 |
| 48 |
* @param object $order object of order parameters. |
| 49 |
* @return array |
| 50 |
*/ |
| 51 |
public function get_coupon_data( $order ) { |
| 52 |
if ( empty( $order->get_items( 'coupon' ) ) ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
foreach ( $order->get_items( 'coupon' ) as $coupon_id => $coupon ) { |
| 57 |
$current_coupon_obj = get_page_by_title( $coupon->get_name(), OBJECT, 'shop_coupon' ); |
| 58 |
$current_coupon_id = $current_coupon_obj->ID; |
| 59 |
$current_coupon = new WC_Coupon( $current_coupon_id ); |
| 60 |
|
| 61 |
$order_data = $current_coupon->get_data(); |
| 62 |
} |
| 63 |
|
| 64 |
return $order_data['code']; |
| 65 |
} |
| 66 |
} |
| 67 |
|