Skip to content

Instantly share code, notes, and snippets.

@KoolPal
KoolPal / add-cron-task.php
Created February 22, 2020 06:05 — forked from damiencarbery/add-cron-task.php
WP Cron - how to use and how to extend
<?php
// Set up task when plugin is activated
register_activation_hook(__FILE__, 'dcwd_cron_status_setup_schedule');
// On an early action hook, check if the hook is scheduled - if not, schedule it.
function dcwd_cron_status_setup_schedule() {
// Add the event only if it is not already scheduled.
if ( ! wp_next_scheduled( 'dcwd_cron_status_status_email' ) ) {
// Schedule weekly at 2:12am.
wp_schedule_event( mktime(2,12,0), 'weekly', 'dcwd_cron_status_status_email');
@KoolPal
KoolPal / woocommerce-stock-info.php
Created February 22, 2020 06:32 — forked from damiencarbery/woocommerce-stock-info.php
List stock levels in WooCommerce - List the stock level for each product and variation. https://www.damiencarbery.com/2019/10/list-stock-levels-in-woocommerce/
<?php
/*
Plugin Name: WooCommerce Stock Info
Plugin URI: https://www.damiencarbery.com/2019/10/list-stock-levels-in-woocommerce/
Description: List the stock level for each product and variation.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
@KoolPal
KoolPal / wc-add-custom-product-field.php
Created February 26, 2020 09:45
WooCommerce functions
/* Add Custom field to WooCommerce product */
add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
function wc_custom_add_custom_fields() {
woocommerce_wp_text_input( array(
'id' => '_delivery_field',
'label' => __( 'Delivery', 'pvc' ),
'description' => __( 'Enter the delivery time in days.', 'pvc' ),
'desc_tip' => 'true'
) );
}
@KoolPal
KoolPal / low-stock-notification-custom-fields.php
Created March 6, 2020 05:57 — forked from fariasf/low-stock-notification-custom-fields.php
Low stock notification per product (adding custom fields)
<?php
/**
* Custom product field to set low stock threshold
* Requires WooCommerce 3.0
*/
function sp_custom_product_stock_threshold_field() {
global $post;
woocommerce_wp_text_input( array(
<?php
// display text after flatsome cart sidebar
function display_text_after_flatsome_cart_sidebar()
{
echo '<b style="color:red; font-size:20px;">Limited time offer</b>';
}
add_action('flatsome_cart_sidebar', 'display_text_after_flatsome_cart_sidebar');
<?php
//flatsome display text after product detail page image, if product is on sale
function display_flatsome_after_product_images() {
global $product;
if ( $product->is_on_sale() )
{
echo '<div style="color:red; border:1px solid #ccc;">Limited time offer</div>';
}
@KoolPal
KoolPal / Posted On - Byline
Created March 17, 2020 12:49 — forked from c-askew/Posted On - Byline
PHP Functions to add to Function.php to make various element contents easily edittable with CSS. Included so far - > Blog Posts "Posted On" & "Byline" - Edit inside post-pre / byline-pre spans
if ( ! function_exists( 'flatsome_posted_on' ) ) :
// Prints HTML with meta information for the current post-date/time and author.
function flatsome_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
// Place this in a text widget
<p class="mb-0"><i class="icon-checkmark cc-checkmark"></i> Worldwide shipping</p>
// Aditional CSS Flatsome > Advanced > Custom CSS
.icon-checkmark.cc-checkmark {
color: #7a9c59;
margin-right: 5px;
}
<?php
//flatsome product detail page text after excerpt
function display_after_short_description($excerpt) {
$add_to_excerpt = $excerpt . "<p style='color:green'>Add anything after excerpt</p>";
return $add_to_excerpt;
}
<?php
/*
Flatsome Theme Product On-Sale End Counter
*/
function display_onsale_product_counter() {
global $product;
if ( $product->is_on_sale() )