Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / functions.php
Created December 30, 2024 11:38
Create a new gift card product if there are no existing gift card product in the store - By WebTOffee(WebToffee Gift Cards (Basic))
<?php //Do not copy this line of code
add_action('admin_init', 'wt_gc_add_demo_giftcard_product');
function wt_gc_add_demo_giftcard_product() {
$existing_product = get_posts(array(
'post_type' => 'product',
'post_status' => array('publish', 'draft', 'pending', 'private', 'future', 'trash'),
'meta_query' => array(
'relation' => 'AND',
array(
@webtoffee-git
webtoffee-git / functions.php
Created December 12, 2024 09:21
Alter the product brand in the feed file with respective to the category that the product belongs to - By WebToffee (WooCommerce Product Feed and Sync Manager)
<?php //Do not copy this line of code
add_filter('wt_feed_filter_product_brand', 'wt_feed_filter_product_brand', 10, 2);
function wt_feed_filter_product_brand($brand, $product) {
$category_id = 38; // Replace with your category ID
$pid = $product->get_id();
if ($product->is_type('variation')) {
$pid = $product->get_parent_id();
@webtoffee-git
webtoffee-git / functions.php
Created December 11, 2024 11:14
Code to alter order billing and shipping state code to state names - By WebToffee (Order import export plugin for woocommere)
<?php //Do not copy this line of code
add_filter('hf_alter_csv_order_data', 'hf_alter_csv_order_data_callback', 10, 2);
function hf_alter_csv_order_data_callback($order_export_data, $filter_args ) {
$order_id = $order_export_data['order_id'];
if( $order_id ){
$order = wc_get_order($order_id);
// Get the shipping state code from the order
@webtoffee-git
webtoffee-git / functions.php
Created December 9, 2024 05:42
Alter Facebook catalog feed product ID to only include the post ID instead of SKU_ID - WooCommerce Product feed by WebToffee
<?php //Do not copy this line of code
add_filter('wt_feed_facebook_product_id', 'wt_feed_facebook_product_id', 10, 3);
function wt_feed_facebook_product_id($fb_retailer_id, $product, $form_data) {
return $product->get_id();
}
@webtoffee-git
webtoffee-git / functions.php
Last active April 11, 2025 11:31
Code for showing total column in packingslip - By WebToffee ( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels )
<?php //do not copy this line of code
add_filter( 'wf_pklist_alter_product_table_head', 'add_total_wieght_column_head', 10, 3);
function add_total_wieght_column_head( $columns_list_arr, $template_type, $order ) {
if ( 'packinglist' === $template_type ) {
if ( isset( $columns_list_arr['-total_weight'] ) ) {
$columns_list_arr['total_weight'] = $columns_list_arr['-total_weight'];
unset( $columns_list_arr['-total_weight'] );
}
}
@webtoffee-git
webtoffee-git / functions.php
Created November 27, 2024 04:31
Code snippet to remove price and total price column form delivery note - By WebToffee ( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels )
<?php //Do not copy this line of code
add_filter('wf_pklist_alter_product_table_head', 'wt_pklist_remove_columns', 10, 3);
function wt_pklist_remove_columns($columns_list_arr, $template_type, $order) {
if ( 'deliverynote' === $template_type && is_array( $columns_list_arr ) ) {
unset( $columns_list_arr['total_price'] );
unset( $columns_list_arr['price'] );
}
return $columns_list_arr;
@webtoffee-git
webtoffee-git / functions.php
Last active November 26, 2024 11:53
Filter to add conversion link - By WebToffee (Product Feed for WooCommerce By WebToffee)
<?php //Do not add this line of code
add_filter('wt_feed_filter_product_link','wt_feed_filter_product_link_utm', 10, 2);
function wt_feed_filter_product_link_utm($link, $product){
return $link.'?utm_source=summer-sale&utm_medium=feed&utm_campaign=summer-sale';
}
@webtoffee-git
webtoffee-git / functions.php
Last active November 21, 2024 11:41
Code snippet to import specific category of products only - By WebToffee (Product import export plugin for WooCommerce)
<?php //Do not add this line of code
function wt_iew_category_custom_filter_import_file($file_name, $path) {
$file_pa = fopen($path, 'r');
while (($line = fgetcsv($file_pa)) !== FALSE) {
$lines[] = $line;
}
fclose($file_pa);
if (!empty($lines[0])) {
$header = $lines[0]; // Assuming the header is in the first row
@webtoffee-git
webtoffee-git / functions.php
Created November 11, 2024 06:15
Code snippet to alter product image URL in documents - by WebToffee ( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels (free)
<?php //Do not copy this line of code
add_filter('wt_pklist_alter_product_image_url', 'wt_pklist_alter_product_image_url_fn', 10, 4);
/**
* Filter to customize the product image URL in packing lists.
*
* This function allows you to set a custom image URL for a product.
* If a custom image URL is available, update the `$img_url` variable to use that URL.
* @return string The updated image URL to be used in the packing list.
*/
function wt_pklist_alter_product_image_url_fn($img_url, $product_id, $variation_id, $parent_id) {
@webtoffee-git
webtoffee-git / functions.php
Created November 5, 2024 11:24
Code snippet to modify the order date format in documents - By WebToffee( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels (free))
<?php //Do not add this line of code
add_filter('wf_pklist_alter_order_date', 'wt_pklist_change_order_date_format', 10, 3);
function wt_pklist_change_order_date_format($order_date, $template_type, $order) {
if ( is_object( $order ) ) {
$order_id = is_object($order) ? $order->get_id() : '';
$order_date_format = 'd/m/y';
$order_date = get_the_date( $order_date_format, $order_id );
}