Skip to content

Instantly share code, notes, and snippets.

@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>';
}
{
"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
{
"product": {
"stock_quantity": 2
}
}
{
"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,
@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';
}
<?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: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 );
@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 / untitled
Created February 7, 2018 05:42
functions.php
add_action( 'init', 'custom_init', 999 );
function custom_init() {
$order = wc_get_order( 123 );
$order->set_payment_method_title( 'Credit Card' );
}
@SirDarcanos
SirDarcanos / functions.php
Created February 12, 2018 06:04
functions.php
add_filter( 'woocommerce_get_script_data', 'my_strength_meter_custom_strings', 10, 2 );
function my_strength_meter_custom_strings( $data, $handle ) {
if ( 'wc-password-strength-meter' === $handle ) {
$data_new = array(
'i18n_password_error' => esc_attr__( 'Come on, enter a stronger password.', 'theme-domain' ),
'i18n_password_hint' => esc_attr__( 'The password should be at least seven characters long.', 'theme-domain' )
);
$data = array_merge( $data, $data_new );
}