Skip to content

Instantly share code, notes, and snippets.

View Auke1810's full-sized avatar
🏠
Working from home

Auke Jongbloed Auke1810

🏠
Working from home
View GitHub Profile
@Auke1810
Auke1810 / use_original_description.php
Last active April 6, 2020 08:19
use the original description without stripping away all the line breaks and paragraph tags from the description field.
// use the original description without stripping away all the line breaks and paragraph tags from the description field.
function use_original_description( $data, $feed_id, $product_id ) {
// Only use the original description in the feed with the given ID (in this case 2)
// remove if you want this for all feeds.
if($feed_id == 2 ){
// Get the product.
$wc_product = wc_get_product( $product_id );
@Auke1810
Auke1810 / strip_html-description-attribute
Last active April 25, 2022 10:05
remove all html tags from the description tag
<?php
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// Strip html from description attributes
// allow given tags with allowedTags
$allowedTags = "";
$attributes['description'] = strip_tags($attributes['description'], $allowedTags);
// IMPORTANT! Always return the $attributes
@Auke1810
Auke1810 / alter_feed_atribute_description
Last active February 19, 2024 09:45
Create clean description attribute by removing html, VC en DIVI markup etc.
/**
* Create clean description attribute by removing html, VC en DIVI markup etc.
* @param array $attributes variable is an array that contains all the product data that goes into the feed.
* @param Int $feed_id makes it possible to only edit a specific feed. You can find the id of a feed in the url of the Feed Editor
* @param Int $product_id makes it possible to select a specific product id that you want to filter.
* @return array.
*/
function alter_feed_description_item( $attributes, $feed_id, $product_id ) {
// Remove WordPress shortcodes from Description
@Auke1810
Auke1810 / use-parent-description-for-product-variations.php
Last active July 14, 2020 11:03
Use parent description for product variations. By default the woocommerce product feed manager will use the description from the product variation. This code will make sure you use the parent product description for every product variation.
/**
* Use parent description for product variations
*/
function use_parent_description_for_product_variations( $data, $feed_id, $product_id ) {
$wc_product = wc_get_product( $product_id );
if ( $wc_product && ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) ) {
$parent_id = $wc_product->get_parent_id( 'feed' );
$wc_parent = wc_get_product( $parent_id );
@Auke1810
Auke1810 / gist:827256dfbea142fbed119b892f463d10
Created February 14, 2019 15:14
Remove multiple characters from feed
/**
* Alter Product feed item
* remove multiple characters from attribute
*/
function alter_feed_description_attribute( $attributes, $feed_id, $product_id ) {
global $product;
// Remove multiple characters from attribute
$remove = [",", ":", ";"];
$attributes['description'] = str_replace($remove, '', $attributes['description']);
@Auke1810
Auke1810 / gist:202a0a96614f5ae36625516ccd4a0ffc
Created February 13, 2019 22:29
The wppfm_cdata_keys() function makes it possible to add attributes to be included in CDATA bracket.
function expand_cdata_attributes( $cdata_attributes ) {
// price and availability attributes are added to the list of attributes that are included in a CDATA bracket
array_push( $cdata_attributes, 'price', 'availability' );
return $cdata_attributes;
}
add_filter( 'wppfm_cdata_keys', 'expand_cdata_attributes' );
@Auke1810
Auke1810 / header.php
Last active January 16, 2019 09:18
Easily add the correct structured data using JSON-LD Google Merchant, this includes the missing microdata for condition.
<?php
// Locate the file header.php in your theme
// Before editing header.php, always make a backup so that you can roll back if something goes wrong.
// At the bottom of the header, simple add the code below
// Verify that you have done it correctly by checking the page with Google’s Structured Data Testing Tool
// https://search.google.com/structured-data/testing-tool
if (isset($product)){
$meta = get_post_meta(get_the_ID());
$_product = new WC_Product(get_the_ID());
if ($_product->regular_price!=NULL){
@Auke1810
Auke1810 / alter_feed_price_item_remove_thousand_seperator.php
Last active June 13, 2022 19:43
remove the thousand seperator from the price item in a feed created with wp product feed manager.
<?php
function alter_feed_price_item_remove_thousand_seperator( $attributes, $feed_id, $product_id ) {
global $product;
$product = wc_get_product( $product_id );
$product_price = $attributes['price'];
// show price without thousand separator and . as decimal separator
$attributes['price'] = number_format( $product_price, 2, '.', '') . " EUR";
// price will look like 1234.57
@Auke1810
Auke1810 / woocomerce-multipl-currencies-support.php
Last active July 27, 2018 16:38
This little script will help you to use the woocomerce multiple currencies with our woocommerce product feed manager. You are able to create several feeds with different currencies.
<?php
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// In this example I have added the "custom_label_0" to each feed.
// Custom_label_0 is filled with a ISO currency code as a static value
// Forinstance the ISO currency code for the US is USD.
// uses wmc_get_price() from woocomerce multiple currencies
//get the correct price in the correct currency.
@Auke1810
Auke1810 / convert-attribute-to-uppercase.php
Last active August 3, 2018 11:26
Convert Attribute to Uppercase
<?php
/**
* Alter Product feed item
* Uppercase a source value (attribute_pa_cup) and combine with an other source value in the size attribute
*/
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// get values
$attribute_pa_band = $attributes['custom_label_0']; //add the attribute_pa_band to attribute "custom_label_0"