| 1 |
<?php |
| 2 |
/** |
| 3 |
* Welcart Purchase Functions |
| 4 |
* |
| 5 |
* Functions for Purchase related. |
| 6 |
* |
| 7 |
* @package Welcart |
| 8 |
*/ |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Function to get information about the products in the cart buyer is purchasing. |
| 14 |
* |
| 15 |
* @since 2.2.2 |
| 16 |
* |
| 17 |
* @param boolean $decode Set this parameter to "true" to decode urlencoded characters. |
| 18 |
* @return array cart data. If there is no item in the cart returns an empty array. |
| 19 |
*/ |
| 20 |
function wel_get_cart( $decode = false ) { |
| 21 |
global $usces; |
| 22 |
$carts = $usces->cart->get_cart(); |
| 23 |
|
| 24 |
foreach ( $carts as $index => $cart_row ) { |
| 25 |
|
| 26 |
$carts[ $index ]['post_id'] = $cart_row['post_id']; |
| 27 |
$carts[ $index ]['price'] = $cart_row['price']; |
| 28 |
$carts[ $index ]['unit_price'] = $cart_row['unit_price']; |
| 29 |
$carts[ $index ]['quantity'] = $cart_row['quantity']; |
| 30 |
|
| 31 |
if ( true === $decode ) { |
| 32 |
$carts[ $index ]['sku'] = urldecode( $cart_row['sku'] ); |
| 33 |
|
| 34 |
$options = array(); |
| 35 |
foreach ( $cart_row['options'] as $key => $value ) { |
| 36 |
$options[ urldecode( $key ) ] = urldecode( $value ); |
| 37 |
} |
| 38 |
$carts[ $index ]['options'] = $options; |
| 39 |
} |
| 40 |
} |
| 41 |
return $carts; |
| 42 |
} |
| 43 |
/** |
| 44 |
* Function to get purchaser information and purchase conditions. |
| 45 |
* |
| 46 |
* @since 2.2.2 |
| 47 |
* |
| 48 |
* @return array Entries data. If there is no item in the cart returns an initial array. |
| 49 |
*/ |
| 50 |
function wel_get_entry() { |
| 51 |
global $usces; |
| 52 |
$entries = $usces->cart->get_entry(); |
| 53 |
|
| 54 |
return $entries; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Function to get total amount of items in the cart. |
| 59 |
* |
| 60 |
* @since 2.2.2 |
| 61 |
* |
| 62 |
* @param boolean $crform Set this parameter to "true" to add currency symbol etc. |
| 63 |
* @return int|string Total amount. If there is no item in the cart returns an empty array. |
| 64 |
*/ |
| 65 |
function wel_get_total_amount_in_cart( $crform = false ) { |
| 66 |
global $usces; |
| 67 |
$price = $usces->get_total_price(); |
| 68 |
|
| 69 |
if ( $crform ) { |
| 70 |
$res = usces_crform( $price, true, false, 'return' ); |
| 71 |
} else { |
| 72 |
$res = $price; |
| 73 |
} |
| 74 |
return $res; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Campaign discount message. |
| 79 |
* Welcart Basic Template Tag. |
| 80 |
* |
| 81 |
* @since 2.2.3 |
| 82 |
* |
| 83 |
* @param int $post_id Post ID. |
| 84 |
* @param string $out Outpu type. If the value of $out is 'return', return; otherwise, echo. |
| 85 |
* |
| 86 |
* @return string Message. |
| 87 |
*/ |
| 88 |
function wel_campaign_message( $post_id = 0, $out = 'out' ) { |
| 89 |
global $post, $usces; |
| 90 |
|
| 91 |
if ( 0 === $post_id ) { |
| 92 |
$post_id = $post->ID; |
| 93 |
} |
| 94 |
|
| 95 |
$html = ''; |
| 96 |
$options = $usces->options; |
| 97 |
|
| 98 |
if ( 'Promotionsale' === $options['display_mode'] && in_category( (int) $options['campaign_category'], $post_id ) ) { |
| 99 |
|
| 100 |
if ( 'discount' === $options['campaign_privilege'] && ! empty( $options['privilege_discount'] ) ) { |
| 101 |
$html = '<div class="campaign_message campaign_discount">' . sprintf( __( '%d% OFF', 'usces' ), $options['privilege_discount'] ) . '</div>'; |
| 102 |
} elseif ( 'point' === $options['campaign_privilege'] && ! empty( $options['privilege_point'] ) ) { |
| 103 |
$html = '<div class="campaign_message campaign_point">' . sprintf( __( '%d times more points', 'usces' ), $options['privilege_point'] ) . '</div>'; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
$html = apply_filters( 'welcart_basic_filter_campaign_message', $html, $post_id ); |
| 108 |
|
| 109 |
if ( 'return' === $out ) { |
| 110 |
return $html; |
| 111 |
} else { |
| 112 |
echo wp_kses_post( $html ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Whether or not the cart contains regular merchandising items. |
| 118 |
* Welcart Basic Template Tag. |
| 119 |
* |
| 120 |
* @since 2.2.3 |
| 121 |
* |
| 122 |
* @return boolean |
| 123 |
*/ |
| 124 |
function wel_have_shipped() { |
| 125 |
$shipped = true; |
| 126 |
if ( defined( 'WCEX_DLSELLER' ) ) { |
| 127 |
$shipped = dlseller_have_shipped(); |
| 128 |
} |
| 129 |
return $shipped; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Curt page URL. |
| 134 |
* Welcart Basic Template Tag. |
| 135 |
* |
| 136 |
* @since 2.2.3 |
| 137 |
* |
| 138 |
* @return string URL. |
| 139 |
*/ |
| 140 |
function wel_get_cart_url() { |
| 141 |
global $usces; |
| 142 |
$cart_url = USCES_CART_URL . $usces->delim; |
| 143 |
return $cart_url; |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Whether there are digital or service items in the cart. |
| 148 |
* Welcart Basic Template Tag. |
| 149 |
* |
| 150 |
* @since 2.2.3 |
| 151 |
* |
| 152 |
* @return boolean |
| 153 |
*/ |
| 154 |
function wel_have_dlseller_content() { |
| 155 |
if ( function_exists( 'dlseller_has_terms' ) ) { |
| 156 |
$res = ( defined( 'WCEX_DLSELLER' ) && dlseller_have_dlseller_content() && dlseller_has_terms() ) ? true : false; |
| 157 |
} else { |
| 158 |
$res = ( defined( 'WCEX_DLSELLER' ) && dlseller_have_dlseller_content() ) ? true : false; |
| 159 |
} |
| 160 |
return $res; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Subscription history of logged-in members. |
| 165 |
* Welcart Basic Template Tag. |
| 166 |
* |
| 167 |
* @since 2.2.3 |
| 168 |
*/ |
| 169 |
function wel_autodelivery_history() { |
| 170 |
$html = ''; |
| 171 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 172 |
$html = wcad_autodelivery_history( 'return' ); |
| 173 |
} |
| 174 |
echo wp_kses_post( $html ); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Whether there are digital or service items in the cart. |
| 179 |
* Welcart Basic Template Tag. |
| 180 |
* |
| 181 |
* @since 2.2.3 |
| 182 |
* |
| 183 |
* @return boolean |
| 184 |
*/ |
| 185 |
function wel_have_ex_order() { |
| 186 |
$ex_order = false; |
| 187 |
if ( defined( 'WCEX_DLSELLER' ) ) { |
| 188 |
$ex_order = ( ! dlseller_have_dlseller_content() && ! dlseller_have_continue_charge() ) ? false : true; |
| 189 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 190 |
$ex_order = wcad_have_regular_order(); |
| 191 |
} |
| 192 |
return $ex_order; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Display the password policy. |
| 197 |
* Welcart Basic Template Tag. |
| 198 |
* |
| 199 |
* @since 2.2.3 |
| 200 |
*/ |
| 201 |
function wel_password_policy_message() { |
| 202 |
if ( function_exists( 'usces_password_policy_message' ) ){ |
| 203 |
usces_password_policy_message(); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Whether the product can use points. |
| 209 |
* Welcart Basic Template Tag. |
| 210 |
* |
| 211 |
* @since 2.2.3 |
| 212 |
* |
| 213 |
* @return boolean |
| 214 |
*/ |
| 215 |
function wel_is_available_point() { |
| 216 |
$res = true; |
| 217 |
if ( function_exists( 'usces_is_available_point' ) ) { |
| 218 |
$res = usces_is_available_point(); |
| 219 |
} else { |
| 220 |
if ( defined( 'WCEX_DLSELLER_VERSION' ) && function_exists( 'dlseller_have_continue_charge' ) ) { |
| 221 |
if ( dlseller_have_continue_charge() ) { |
| 222 |
$res = false; |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
return $res; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Get Charging Type. |
| 231 |
* Welcart Basic Template Tag. |
| 232 |
* |
| 233 |
* @since 2.2.3 |
| 234 |
* |
| 235 |
* @param int $post_id Post ID. |
| 236 |
* @return string ChargingType( service|data|shipped ). |
| 237 |
*/ |
| 238 |
function wel_get_item_chargingtype( $post_id = 0 ) { |
| 239 |
global $post, $usces; |
| 240 |
|
| 241 |
if ( 0 === $post_id ) { |
| 242 |
$post_id = $post->ID; |
| 243 |
} |
| 244 |
|
| 245 |
$charging = $usces->getItemChargingType( $post_id ); |
| 246 |
|
| 247 |
if ( 'continue' === $charging && ! defined( 'WCEX_DLSELLER' ) ) { |
| 248 |
$charging = ''; |
| 249 |
} |
| 250 |
|
| 251 |
if ( 'regular' === $charging && ! defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 252 |
$charging = ''; |
| 253 |
} |
| 254 |
|
| 255 |
return $charging; |
| 256 |
} |
| 257 |
|