Skip to content

Instantly share code, notes, and snippets.

/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@SirDarcanos
SirDarcanos / functions.php
Last active December 8, 2023 14:17
How to Show the Product Short Description on the Shop Page
<?php
add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 6 );
function woo_show_excerpt_shop_page() {
global $product;
echo '<p class="short-description">' . $product->post->post_excerpt . '</p>';
}
$foods = array(
array(
'id' => 4,
'name' => 'Banana',
'color' => 'Yellow',
),
array(
'id' => '5',
'name' => 'Apple',
'color' => 'Red',
function is_streamer_live( $channel, $client_id ) {
// Get current status
$url = 'https://api.twitch.tv/kraken/streams/' . esc_html( trim( $channel, '/' ) ) . '?client_id=' . esc_html( $client_id );
$response = wp_remote_get( $url );
if ( ! is_wp_error( $response ) && $response['response']['code'] === 200 ) {
$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( empty( $body->stream ) ) {
return false;
<label for="nyp">
<?php
global $product;
$text = '';
switch ( $product->id ) {
case 1:
$text = 'Text for product ID 1';
break;
<?php
// Get the value of the post meta with name `_my_post_meta_name`
$post_meta_value = get_post_meta( $post->ID, '_my_post_meta_name', true );
// Print the post meta value
printf( 'The value of my post meta is %s', $post_meta_value );
/**
* Remove the additional CSS section, introduced in 4.7, from the Customizer.
* @param $wp_customize WP_Customize_Manager
*/
function mycustomfunc_remove_css_section( $wp_customize ) {
$wp_customize->remove_section( 'custom_css' );
}
add_action( 'customize_register', 'mycustomfunc_remove_css_section', 15 );
/**
* Remove the additional CSS section, introduced in 4.7, from the Customizer.
* @param $wp_customize WP_Customize_Manager
*/
function mycustomfunc_remove_css_section( $wp_customize ) {
$user = wp_get_current_user();
if ( ! $user->has_cap( 'manage_options' ) ) {
$wp_customize->remove_section( 'custom_css' );
}
/**
* Remove the additional CSS section, introduced in 4.7, from the Customizer.
* @param $wp_customize WP_Customize_Manager
*/
function mycustomfunc_remove_css_section( $wp_customize ) {
$user = wp_get_current_user();
if ( $user->ID !== 1 ) {
$wp_customize->remove_section( 'custom_css' );
}
/**
* Adds a new item into the Bulk Actions dropdown.
*/
function register_my_bulk_actions( $bulk_actions ) {
$bulk_actions['draft_posts'] = __( 'Move to Draft', 'domain' );
return $bulk_actions;
}
add_filter( 'bulk_actions-edit-post', 'register_my_bulk_actions' );