Skip to content

Instantly share code, notes, and snippets.

View thesadoo's full-sized avatar

Sadoo Alizad thesadoo

View GitHub Profile
@thesadoo
thesadoo / no_order_pay_links.php
Created April 4, 2021 02:06
in #woocommerce if you wanna get rid of the pay (or cancel/view) action link in orders page you can use this simple tiny piece of code that filters the action link items for an order in user account's orders page. Mind that this practice doesn't stop order pay link stop working, it merely stops them from showing in user profile page orders list.
@thesadoo
thesadoo / wc_remove_cat_hierarchy.php
Last active January 12, 2018 06:50
Remove WooCommerce hierarchical product category URL rewrites
<?php
# the neat way using WooCommerce filter
function remove_wc_product_cat_hierarchy($args){
$args['rewrite']['hierarchical'] = false;
return $args;
}
add_filter('woocommerce_taxonomy_args_product_cat', 'remove_wc_product_cat_hierarchy');
@thesadoo
thesadoo / getTelegramAvatar.php
Created July 21, 2017 19:34
Get user's Telegram avatar with a simple function using their Telegram usernames
<?php
function getTelegramAvatar($username='')
{
$username = $username;
$username = str_replace('@', '', $username);
$baseURL = 'https://telegram.me/';
$pageURL = $baseURL . $username;
@thesadoo
thesadoo / woocommerce_default_city.php
Created November 17, 2016 23:29
WooCommerce set default values in checkout page for shipping/billing fields. I used it to set a default city.
<?php
add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
// You can use this for postcode, address, company, first name, last name and such.
// field names can be found here:
// https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
// found the main function woocommerce_form_field() here:
// https://github.com/woocommerce/woocommerce/blob/76b32c9aa52ebac70fe5a60a8d56351218760471/includes/wc-template-functions.php
function default_values_checkout_fields( $fields ) {
@thesadoo
thesadoo / woocommerce_show_the_orders_in_account.php
Created October 13, 2016 18:13
Show all the woocommerce orders in "my account" page (there is a limit after 2.6)
<?php
function woocommerce_show_all_the_orders_in_account($arr){
$arr['limit'] = -1;
return $arr;
}
add_filter('woocommerce_my_account_my_orders_query', 'woocommerce_show_all_the_orders_in_account');
?>
@thesadoo
thesadoo / separated-post-title-word-by-word.php
Created October 3, 2016 11:39
SpannyTitle: Space separated post titles (separated into numbered span tags)
<?php
public function SpannyTitle( $id = null, $return = true){
$pid = ($id) ? $id : get_the_ID();
$title = get_the_title($pid);
$title = explode(' ', $title);
foreach( $title as $titlenum => $titletext ){
$titlenew .= '<span class="title-num-' . ($titlenum + 1) . '">' . $titletext . ' </span>';
}
if( $return ){
@thesadoo
thesadoo / woo-add-products-along-posts-in-feed.php
Created October 3, 2016 11:32
Add WooCommerce products to website's feed along posts
<?php
# ADD PRODUCTS TO THE FEED
add_action('pre_get_posts', 'add_products_to_the_feed');
function add_products_to_the_feed($query){
if( is_feed() && is_main_query() ){
$query->set('post_type', array('post', 'product'));
}
@thesadoo
thesadoo / woo-discount-percentage-function.php
Last active October 3, 2016 11:33
Get WooCommerce product's discount percentage with a function
<?php
function off_percentage($id=null){
$pid = ($id) ? $id : get_the_ID();
$product = new WC_Product($pid);
$sale_price = $product->sale_price;
$regu_price = $product->regular_price;
$percentage = round( ( ( $regu_price - $sale_price ) / $regu_price ) * 100 );
return $percentage;
}
@thesadoo
thesadoo / woo-discount-percentage-in-loop.php
Created October 3, 2016 11:28
Get WooCommerce product's discount percentage
<?php
global $product;
$sale_price = $product->sale_price;
$regu_price = $product->regular_price;
$percentage = round( ( ( $regu_price - $sale_price ) / $regu_price ) * 100 );
?>
@thesadoo
thesadoo / ThumbnailAddress.php
Last active October 3, 2016 11:28
Wordpress post thumbnail URL
<?php
function ThumbnailAddress( $id = false, $echo = true, $size = "fullsize" ) {
global $post;
if( !$id ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), $size );
} else {
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($id), $size );
}
if( $echo == true ){