Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
😄

Yu-Cheng Wang ucheng

💭
😄
View GitHub Profile
@ucheng
ucheng / php-pdf.php
Last active Jun 23, 2022
Display pdf content in browser
View php-pdf.php
<?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
EDD x ECPay Payment Gateway
View edd-ecpay.php
<?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
View customer_ip.php
/**
* 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 Apr 22, 2021
build custom shipping address
View build_custom_shipping_address.php
<?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 Jun 7, 2020
Remove Marketing Hub in WooCommerce Admin
View remove_marketing_hub
<?php
add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );
@ucheng
ucheng / show_customer_linked_affiliate.php
Created Apr 28, 2020
show customer linked affiliate
View show_customer_linked_affiliate.php
<?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);
View display_message_on_thankyou_page.php
/* -----
* 若您希望全部訂單都顯示,請將以下內容加入 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 Aug 18, 2018
bulk add user to subscription
View bulk_add_user_to_subscription.php
<?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 Jan 8, 2018
adjust photon image quality
View photon.php
<?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 Oct 6, 2017
限制購買同分類下的商品
View limited_purchased_in_same_cat.php
<?php
//不可重複購買的分類(可多個)
global $non_repeatable_cats;
$non_repeatable_cats = array( 21, 22 );
function foo_wc_purchase_disabled_message() {
global $product,$non_repeatable_cats;