PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.8
WpStream – Live Streaming, Video on Demand, Pay Per View v4.8
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / hello-wpstream / framework / woocommerce-functions.php

woocommerce-functions.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.8, at hello-wpstream/framework/woocommerce-functions.php

153 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woocommerce functions
4 *
5 * @package wpstream-theme
6 */
7
8 // Require class wc product bundle.
9 if ( class_exists( 'WooCommerce' ) ) {
10 require_once 'class-wc-product-wpstream-bundle.php';
11 }
12
13 add_filter( 'woocommerce_form_field_args', 'wpstream_theme_custom_remove_class_from_labels', 10, 3 );function wpstream_theme_custom_remove_class_from_labels( $args, $key, $value ) {
14 // Specify the class you want to remove
15 $class_to_remove = 'screen-reader-text';
16
17 // Check if the label_class is set and contains the class we want to remove
18 if ( isset( $args['label_class'] ) && ($key = array_search($class_to_remove, $args['label_class'])) !== false ) {
19 unset($args['label_class'][$key]);
20 }
21
22 return $args;
23 }
24
25
26 add_action( 'woocommerce_before_related_products', 'wpstream_before_related_products' );
27 /**
28 * Output custom content before the related products section.
29 */
30 function wpstream_before_related_products() {
31 echo '<p>This is some custom text before the related products:</p>';
32 }
33
34 /**
35 * Save extra fields on account save.
36 *
37 * @param int $user_id The user ID.
38 */
39 function wpstream_save_extra_fields_on_account_save( $user_id ) {
40 // Verify nonce.
41 if ( ! isset( $_POST['woocommerce-save-account-details-nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['woocommerce-save-account-details-nonce'] ) ), 'save_account_details' ) ) {
42 return;
43 }
44
45 if ( isset( $_POST['custom_picture'] ) ) {
46 update_user_meta( $user_id, 'custom_picture', sanitize_text_field( wp_unslash( $_POST['custom_picture'] ) ) );
47 }
48 if ( isset( $_POST['custom_picture_small'] ) ) {
49 update_user_meta( $user_id, 'custom_picture_small', sanitize_text_field( wp_unslash( $_POST['custom_picture_small'] ) ) );
50 }
51 }
52 add_action( 'woocommerce_save_account_details', 'wpstream_save_extra_fields_on_account_save' );
53
54
55 /**
56 * Remove "Add to Cart" button if product has already been purchased by the customer.
57 *
58 * @param bool $purchasable Whether the product is purchasable.
59 * @param WC_Product $product The product object.
60 * @return bool Whether the product is purchasable.
61 */
62 function wpstream_hide_add_to_cart_if_purchased( $purchasable, $product ) {
63 // Check if the product is already purchased by the current customer.
64 $product_type = $product->get_type();
65
66 if (
67 'video_on_demand' === $product_type ||
68 'live_stream' === $product_type ||
69 'wpstream_bundle' === $product_type ||
70 'subscription' === $product_type
71 ) {
72 $current_user = wp_get_current_user();
73
74 if ( is_user_logged_in() && wc_customer_bought_product( get_current_user_id(), $current_user->user_email, $product->get_id() ) ) {
75 $purchasable = false;
76 }
77 }
78
79 return $purchasable;
80 }
81
82 add_filter( 'woocommerce_is_purchasable', 'wpstream_hide_add_to_cart_if_purchased', 10, 2 );
83
84
85
86 add_filter( 'product_type_selector', 'wpstream_theme_add_products_type' );
87 /**
88 * Add custom product type to WooCommerce.
89 *
90 * @param array $types List of existing product types.
91 * @return array List of product types with the custom one added.
92 */
93 function wpstream_theme_add_products_type( $types ) {
94 $types['wpstream_bundle'] = __( 'Video Collection', 'hello-wpstream' );
95 return $types;
96 }
97
98 /**
99 * Show the general tab for custom product types in WooCommerce.
100 *
101 * @param array $tabs List of product tabs.
102 * @return array Modified list of product tabs.
103 */
104 function wpstream_show_general_tab_for_custom_product( $tabs ) {
105 $tabs['general']['class'][] = 'show_if_live_stream show_if_video_on_demand show_if_wpstream_bundle';
106 return $tabs;
107 }
108
109 add_filter( 'woocommerce_my_account_my_orders_query', 'custom_my_orders_query' );
110
111 /**
112 * Customizes the query for displaying customer orders.
113 *
114 * @param array $args Query arguments.
115 * @return array Modified query arguments.
116 */
117 function custom_my_orders_query( $args ) {
118 $args['posts_per_page'] = 5;
119 return $args;
120 }
121
122
123
124 function wpstream_theme_products_tag($product_id,$product){
125 if ( get_post_type( $product_id ) === 'product') :
126
127 $product_type = $product->get_type();
128
129 switch ($product_type){
130 case "live_stream":
131 ?>
132 <div class="wpstream_featured_image_live_tag wpstream_hide_on_trailer wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'LIVE', 'hello-wpstream' ); ?></div>
133 <?php
134 break;
135 case "video_on_demand":
136 ?>
137 <div class="wpstream_featured_image_vod_tag wpstream_hide_on_trailer wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'VIDEO', 'hello-wpstream' ); ?></div>
138 <?php
139 break;
140 case "wpstream_bundle":
141 ?>
142 <div class="wpstream_featured_image_collection_tag wpstream_hide_on_trailer wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'COLLECTION', 'hello-wpstream' ); ?></div>
143 <?php
144 break;
145 case "subscription":
146 ?>
147 <div class="wpstream_featured_image_subscription_tag wpstream_hide_on_trailer wpstream_featured_image_live_tag--on-description"><?php echo esc_html__( 'SUBSCRIPTION', 'hello-wpstream' ); ?></div>
148 <?php
149 break;
150 }
151 endif;
152
153 }