Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / Functions.php
Created June 9, 2025 10:00
Code Snippet to override the plugin’s CSS style - By WebToffee(Related products plugin)
<?php> //Do not copy this line of code
add_action('wp_footer',function(){
?>
<style>
.wt-related-products .owl-theme .owl-nav { margin-top: 25px !important; }
</style>
<?php
},10);
@webtoffee-git
webtoffee-git / functions.php
Last active June 9, 2025 09:49
Code to import only certain brands - By WebToffee (Product import export basic)
<?php>//Do not copy this line of code
add_filter('wt_iew_importer_do_import_basic', 'filter_products_by_brand', 1, 4);
function filter_products_by_brand($data_arr, $to_process, $step, $selected_template_data) {
// Define allowed brands (normalized to uppercase and trimmed)
$allowed_brands = array_map('strtoupper', array_map('trim', array('Brand1', 'Brand2', 'Brand3')));
foreach ($data_arr as $key => $product) {
if (isset($product['meta_mapping_fields']['taxonomies']['tax:product_brand'])) {
$raw_brand = $product['meta_mapping_fields']['taxonomies']['tax:product_brand'];
@webtoffee-git
webtoffee-git / functions.php
Created June 3, 2025 09:58
Code to change the related product widget heading from h1 to h3 - By WebToffee (Related products Basic plugin)
<?php> //Do not copy this line of code
add_action('wp_footer', function () {
if (is_product()) {
?>
<script>
jQuery(document).ready(function () {
const container = jQuery('.wt-related-products');
if (container.length > 0) {
const h1 = container.find('.wt-crp-heading');
if (h1.length) {
@webtoffee-git
webtoffee-git / functions.php
Last active June 5, 2025 03:44
Code snippet to hide applied coupons and inapplicable coupons from display - By WebToffee (Smart Coupon Basic)
<?php>//Do not copy this line of code
add_filter( 'wt_smart_coupon_display_invalid_coupons', '__return_false' );
add_filter( 'wt_sc_alter_user_coupons', 'wbte_sc_remove_applied_coupons_from_user_coupons' );
if ( ! function_exists( 'wbte_sc_remove_applied_coupons_from_user_coupons' ) ) {
/**
* Remove applied coupons from user coupons list
*
* @param array $post_ids Array of coupon post IDs.
<?php //Do not copy this line of code
add_action('wp_footer', function () {
if (is_product()) {
?>
<script>
jQuery(document).ready(function () {
const container = jQuery('.wt-related-products');
if (container.length > 0) {
const h2 = container.find('.wt-crp-heading');
if (h2.length) {
@webtoffee-git
webtoffee-git / functions.php
Created May 22, 2025 07:14
Code snippet to hide tax items from invoice document - By WebToffee
<?php> //Do not copy this line of code
add_filter('wf_pklist_alter_template_html', 'wt_remove_tax_items_row_from_invoice', 10, 2);
function wt_remove_tax_items_row_from_invoice( $html, $template_type ) {
if ( $template_type === 'invoice' && strpos( $html, 'data-row-type="wfte_tax_items"' ) !== false ) {
// Only run regex if pattern likely exists
$html = preg_replace(
'/<tr[^>]*data-row-type="wfte_tax_items"[^>]*>.*?<\/tr>/is',
'',
$html
);
@webtoffee-git
webtoffee-git / functions.php
Created May 10, 2025 06:55
To hide 'via Fee Total amount' in the Invoice document - By WebToffee ( WooCommerce PDF Invoices, Packing Slips, Delivery Notes, and Shipping Labels)
<?php //do not copy this line of code
add_filter('wf_pklist_alter_find_replace','wf_pklist_alter_fee_details',10,6);
function wf_pklist_alter_fee_details($find_replace, $template_type, $order, $box_packing, $order_package, $html)
{
if($template_type=='invoice')
{
$order_id = (WC()->version < '2.7.0') ? $order->id : $order->get_id();
$user_currency=get_post_meta($order_id, '_order_currency', true);
$fee_details=$order->get_items('fee');
if(!empty($fee_details))
@webtoffee-git
webtoffee-git / functions.php
Created April 28, 2025 09:18
Modify the font size of the text in the Product Table and Summary Table of the Invoice document - By WebToffee ( WooCommerce PDF Invoices, Packing Slips, Delivery Notes, and Shipping Labels)
<?php //do not copy this line of code
add_filter('wf_pklist_alter_template_html', 'wt_pklist_change_product_table_body_bg_font', 10, 2);
function wt_pklist_change_product_table_body_bg_font($html, $template_type) {
if ('invoice' === $template_type) { // or 'packinglist' if needed
$html .= '<style type="text/css">
.wfte_product_table_head th {
font-size: 18px; /* Font size for header */
}
.wfte_product_table_body td,
@webtoffee-git
webtoffee-git / functions.php
Last active April 28, 2025 08:49
Code to Add Product Weight Below Product Name in Email Template - By WebToffee(WebToffee eCommerce Marketing Automation – Email marketing, Popups, Email customizer)
<?php //Do not copy this line of code
add_action('woocommerce_order_item_meta_end', function($item_id, $item, $order, $plain_text) {
$product = $item->get_product();
if (!$product) return;
$weight = $product->get_weight();
if(!empty($weight)){
echo '<br><b class="wt_product_weight">' . __('Weight:', 'woocommerce') . '</b> ' . ($weight . ' ' . get_option('woocommerce_weight_unit') );
}
}
@webtoffee-git
webtoffee-git / functions.php
Created April 11, 2025 11:33
To alter webp product image size in invoice document for mPDF add-on users - 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_columns', 'wt_pklist_alter_product_image_size', 10, 5);
add_filter('wf_pklist_alter_package_product_table_columns', 'wt_pklist_alter_product_image_size', 10, 5);
function wt_pklist_alter_product_image_size($product_row_columns, $template_type, $_product, $order_item, $order) {
if ('invoice' === $template_type) {
$image_id = $_product->get_image_id();
if ($image_id) {
$image_url = wp_get_attachment_url($image_id);