Skip to content

Instantly share code, notes, and snippets.

@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 10:11
Customize the Footer Credits in Storefront
<?php
/**
* Display the theme credit
*
* @since 1.0.0
* @return void
*/
function storefront_credit() {
?>
<div class="site-info">
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 10:13
Set a Default Price for Products
<?php
/**
* Sets the product default price to 10. Only works once, if the price is not specified.
*
* @param int $post_id
* @param object $post
*/
function set_product_default_price( $post_id, $post ) {
$product = wc_get_product( $post_id );
$already_set = get_post_meta( $post_id, '_set_default_price', true );
<?php
function wc_pdf_watermark_extend_template_tags( $parsed_text, $unparsed_text, $order, $product ) {
// Look for {product_title} in text and replace it with the product title
$parsed_text = str_replace( '{product_title}', $product->get_title(), $parsed_text );
return $parsed_text;
}
add_filter( 'woocommerce_pdf_watermark_parse_template_tags', 'wc_pdf_watermark_extend_template_tags', 10, 4 );
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 10:14
Customize Pre-Order Products
<?php
add_filter( 'body_class', 'add_preorder_class' );
add_filter( 'post_class', 'add_preorder_class' );
function add_preorder_class( $classes ) {
global $post;
$product = wc_get_product( $post->ID );
if ( $product && 'yes' === get_post_meta( $product->get_id(), '_wc_pre_orders_enabled', true ) ) {
$classes[] = 'pre-order';
}
{
"product": {
"title": "Premium Quality",
"id": 3487,
"created_at": "2017-11-09T06:20:05Z",
"updated_at": "2017-11-09T06:20:05Z",
"type": "simple",
"status": "publish",
"downloadable": false,
"virtual": false,
{
"product": {
"stock_quantity": 2
}
}
{
"product": {
"title": "Premium Quality",
"type": "simple",
"regular_price": "21.99",
"description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",
"short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
"categories": [
9,
14
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 10:17
Add Text to The Emails Body
<?php
add_action( 'woocommerce_email_header', 'add_email_header', 20 );
function add_email_header() {
echo '<h2>My Heading</h2>';
echo '<p>Add content here</p>';
}
add_action( 'init', 'remove_footer_checkout' );
function remove_footer_checkout() {
if ( is_checkout() ) {
remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
}
}
add_filter( 'booking_form_params', 'change_booking_form_params' );
function change_booking_form_params( $params ) {
$params['i18n_date_unavailable' = 'This date is unavailable';
$params['i18n_date_fully_booked'] = 'This date is fully booked and unavailable';
$params['i18n_date_partially_booked'] = 'This date is partially booked - but bookings still remain';
$params['i18n_date_available'] = 'This date is available';
$params['i18n_start_date'] = 'Choose a Start Date';
$params['i18n_end_date'] = 'Choose an End Date';
$params['i18n_dates'] = 'Dates';
$params['i18n_choose_options'] = 'Please select the options for your booking above first';