This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function action_woocommerce_before_checkout_form($wccm_autocreate_account) { | |
wc_cart_totals_shipping_html(); | |
woocommerce_shipping_calculator('選取運送方式'); | |
}; | |
add_action('woocommerce_before_checkout_form', 'action_woocommerce_before_checkout_form', 10, 1); | |
function woocommerce_shipping_calculator_scripts() { | |
if (is_checkout()) { | |
if (wp_script_is('wc-cart', 'registered') && !wp_script_is('wc-cart', 'enqueued')) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function woocommerce_orders() { | |
$user_id = get_current_user_id(); | |
if ($user_id == 0) { | |
//沒登入就呼叫用戶後台的標準短碼 | |
return do_shortcode('[woocommerce_my_account]'); | |
} else { | |
ob_start(); | |
//登入的用戶就撈 orders 的樣板來顯示訂單資料 | |
wc_get_template('myaccount/my-orders.php', array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (function_exists('gapp_options')) { | |
function gapp_get_total_pageviews($format = true) { | |
$options = gapp_options(); | |
if (empty($options['gapp_token'])) { | |
//還沒授權過就先回傳預設值 | |
return $options['gapp_defaultval']; | |
} | |
//起始日 | |
$startDate = $options['gapp_startdate']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//較早觸發、無法改變付款方式順序 | |
function mxp_woocommerce_payment_gateways($payment_gateways) { | |
// 判斷付款方式的 Class 名稱後根據邏輯比對取消註冊 | |
foreach ($payment_gateways as $key => $gateways) { | |
if ($gateways == "WC_Gateway_COD") { | |
unset($payment_gateways[$key]); | |
} | |
} | |
return $payment_gateways; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mxp_sort_shipping_methods_order($available_shipping_methods, $package) { | |
if (!$available_shipping_methods) { | |
return; | |
} | |
// 運送方式,檢視 radio 元素,找到的 value 值 | |
$sort_order = array( | |
'flat_rate:1' => null, | |
'some_other_shipping_method_slug:3' => null, | |
'flat_rate:2' => null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mxp_sort_shipping_services_by_cost($available_shipping_methods, $package) { | |
if (!$available_shipping_methods) { | |
return; | |
} | |
$rate_cost_set = array(); | |
// 抽出運費多寡 | |
foreach ($available_shipping_methods as $rate) { | |
$rate_cost_set[] = $rate->cost; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function save_data_before_open_new_page($value) { | |
$data = $_POST['post_data']; | |
parse_str(html_entity_decode($data), $pdata); | |
if (isset($pdata['billing_first_name']) && $pdata['billing_first_name'] != "") { | |
WC()->session->set('billing_first_name', $pdata['billing_first_name']); | |
} | |
if (isset($pdata['billing_phone']) && $pdata['billing_phone'] != "") { | |
WC()->session->set('billing_phone', $pdata['billing_phone']); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.get('https://www.mxp.tw/cdn-cgi/trace', function(r) { | |
r = r.split('\n'), a = []; | |
for (var i = 0; i < r.length; ++i) a[r[i].split('=')[0]] = r[i].split('=')[1]; | |
console.log(a['loc']); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function add_privacy_page_edit_cap($caps, $cap, $user_id, $args) { | |
if ('manage_privacy_options' === $cap) { | |
$manage_name = is_multisite() ? 'manage_network' : 'manage_options'; | |
$caps = array_diff($caps, [$manage_name]); | |
} | |
return $caps; | |
} | |
add_filter('map_meta_cap', 'add_privacy_page_edit_cap', 10, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mxp_shipping_fee_discount() { | |
$fee = 0; // 新增運費底價 | |
if (is_admin() && !defined('DOING_AJAX')) { | |
// 避免在管理介面下被觸發 | |
return; | |
} | |
$total_pirce = 0; | |
/* | |
foreach (WC()->cart->get_cart() as $item => $values) { |