Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ucheng's full-sized avatar
💭
😄

Yu-Cheng Wang ucheng

💭
😄
View GitHub Profile
@ucheng
ucheng / php-pdf.php
Last active June 23, 2022 08:43
Display pdf content in browser
<?php
$response = wp_remote_post($url, $args = array());
$header_content = (array) wp_remote_retrieve_headers( $response );
$header = current($header_content);
$data = wp_remote_retrieve_body( $response );
if ( array_key_exists('content-type', $header) ) {
if ( $header['content-type'] === 'application/pdf') {
header("Content-type: application/pdf");
header('Content-Length: '.strlen( $data ));
@ucheng
ucheng / edd-ecpay.php
Created May 28, 2021 00:46
EDD x ECPay Payment Gateway
<?php
// registers the gateway
function pw_edd_register_gateway($gateways) {
$gateways['ecpay_credit'] = array( 'admin_label' => '綠界-信用卡', 'checkout_label' => __('綠界-信用卡', 'your_textdomain'));
return $gateways;
}
add_filter('edd_payment_gateways', 'pw_edd_register_gateway');
// process the payment
@ucheng
ucheng / customer_ip.php
Created May 22, 2021 15:15
get customer ip
/**
* Get customer ip
*
* @return string
*/
private function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
// check ip from share internet
@ucheng
ucheng / build_custom_shipping_address.php
Created April 22, 2021 14:28
build custom shipping address
<?php
// $raw_address = Array (
// [first_name] => YU CHENG
// [last_name] => WANG
// [company] =>
// [address_1] => 新北路
// [address_2] =>
// [city] => 板橋區
// [state] => NEW TAIPEI CITY
// [postcode] => 100
@ucheng
ucheng / remove_marketing_hub
Created June 7, 2020 06:08
Remove Marketing Hub in WooCommerce Admin
<?php
add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );
@ucheng
ucheng / show_customer_linked_affiliate.php
Created April 28, 2020 08:09
show customer linked affiliate
<?php
add_action('show_user_profile', 'mys_additional_profile_fields', 9);
add_action('edit_user_profile', 'mys_additional_profile_fields', 9);
function mys_additional_profile_fields($user)
{
echo '<h2>連結的推薦人</h2>';
$customer = affwp_get_customer($user->user_email);
/* -----
* 若您希望全部訂單都顯示,請將以下內容加入 functions.php 中
----- */
add_action('woocommerce_thankyou', 'shopcom_add_content_thankyou', 5);
function shopcom_add_content_thankyou()
{
echo '<h2 class="h2thanks">提醒您:</h2><p class="pthanks">以下都是詐騙:訂單設錯、訂單金額有誤、設成分期每月扣款、重覆訂購多筆、宅配或超商出錯、簽收單牽成簽帳單、條碼刷錯、重複扣款。歹徒會以更改訂單要求退費給您為由,要求您操作ATM,這些都是詐騙手法。若遇可疑來電,隨時可撥打165反詐騙諮詢專線。</p>';
}
@ucheng
ucheng / bulk_add_user_to_subscription.php
Created August 18, 2018 09:49
bulk add user to subscription
<?php
function oneday_bulk_add_user_to_subscription() {
$args= array(
array( 'role' => 'Subscriber' )
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
@ucheng
ucheng / photon.php
Created January 8, 2018 14:54
adjust photon image quality
<?php
add_filter('jetpack_photon_pre_args', 'jetpackme_custom_photon_compression' );
function jetpackme_custom_photon_compression( $args ) {
$args['quality'] = 80;
$args['strip'] = 'all';
return $args;
}
@ucheng
ucheng / limited_purchased_in_same_cat.php
Last active October 6, 2017 04:49
限制購買同分類下的商品
<?php
//不可重複購買的分類(可多個)
global $non_repeatable_cats;
$non_repeatable_cats = array( 21, 22 );
function foo_wc_purchase_disabled_message() {
global $product,$non_repeatable_cats;