Skip to content

Instantly share code, notes, and snippets.

@furahaclothing
Created July 13, 2014 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furahaclothing/71591dcffed7e498e162 to your computer and use it in GitHub Desktop.
Save furahaclothing/71591dcffed7e498e162 to your computer and use it in GitHub Desktop.
welcart クーポン機能 *エラー表示検証する*
//welcart クーポンコード
add_filter('usces_order_discount', 'coupon_order_discount', 10, 2);
function coupon_order_discount($discount, $cart){
global $usces;
$entry = $usces->cart->get_entry();
$total_items_price = $usces->get_total_price();
if($entry['custom_order']['coupon'] == 'クーポンコード'){
$discount = ceil($total_items_price * 0.1 * -1);
}
return $discount;
}
//クーポン書き換え
add_filter('usces_confirm_discount_label', 'coupon_confirm_discount_label', 10, 1);
function coupon_confirm_discount_label(){
global $usces;
$entry = $usces->cart->get_entry();
$order_id = $_POST['order_id'];
if($entry['custom_order']['coupon'] == 'furaha10' || $usces->get_order_meta_value('csod_coupon', $order_id) == true){
$text = "クーポン割引";
} else {
$text = __('Campaign disnount', 'usces');
}
return $text;
}
//クーポンコードがエラーの時の表示
add_action('usces_filter_confirm_page_header', 'coupon_confirm_page_header', 10, 1);
function coupon_confirm_page_header(){
global $usces;
$entry = $usces->cart->get_entry();
if($entry['custom_order']['coupon'] == true && $entry['custom_order']['coupon'] != "クーポンコード"){
$html .= '<span class="coupon-error">クーポンコードが違います。</span>';
}
return do_shortcode( stripslashes(nl2br($html)) );
}
//クーポン入力フィールドの横にテキスト
add_filter('usces_filter_custom_field_input_value', 'coupon_custom_field_input', 10, 3);
function coupon_custom_field_input($html, $key, $entry){
if($key == 'coupon'){
$html .= '<span class="coupon-text">&nbsp;クーポンコードお持ちの方はご記入下さい。</span>';
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment