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 / set_batch_time.php
Last active October 26, 2023 12:28
Change batch time
View set_batch_time.php
function set_batch_time( $batch_time ) {
// the default batch time limit is set to 30 seconds.
// It means that each 30 seconds a new batch is started or when 90% of the max memory limit is reached.
// use the below time to change the default 30 second limit.
return 20;
}
add_filter( 'wppfm_default_time_limit', 'set_batch_time' );
@Auke1810
Auke1810 / product_old_new.php
Last active May 1, 2023 12:38
Fill in the custom_label_0 with new if the product is created within 10 day's from now.
View product_old_new.php
<?php
function product_old_new( $attributes, $feed_id, $product_id ) {
global $product;
// Get product creat
$product = wc_get_product( $product_id );
$product_created = strtotime($product->get_date_created());
// Calculate the date 10 days ago
View add_availability_date_when_backorder.php
<?php
function add_availability_date_when_backorder( $attributes, $feed_id, $product_id ) {
$wc_product = wc_get_product( $product_id ); // Get the WC_Product Object
if ($wc_product->is_on_backorder() ) {
// add availability_date attribute
$attributes['availability_date'] = gmdate( 'c', strtotime( '+7 days' ) );
}
@Auke1810
Auke1810 / wppfm_add_product_attributes
Created April 12, 2023 10:55
voeg product attributen toe aan een custom product feed.
View wppfm_add_product_attributes
function wppfm_add_product_attributes( $attributes, $feed_id, $product_id ) {
$wc_product = wc_get_product( $product_id ); // Get the WC_Product Object
if ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) {
$product_attributes = $wc_product->get_attributes(); // Get the product attributes
// Loop through the attributes and add them to the $attributes array
foreach ( $product_attributes as $key => $value ) {
if ( $value ) {
$attributes[ $key ] = $value;
@Auke1810
Auke1810 / replace Yoast SEO shortcodes in title and description attribuut
Created April 10, 2023 16:17
This snippet replaces Yoast SEO shortcodes ( '%%title%%', '%%sitename%%','%%sep%%') in title and description attribuut
View replace Yoast SEO shortcodes in title and description attribuut
<?php
function replace_yoast_seo_title( $attributes, $feed_id, $product_id ) {
// replace %%title%% with the product title.
$attributes['title'] = str_replace('%%title%%', get_the_title($product_id), $attributes['title']);
$attributes['description'] = str_replace('%%title%%', get_the_title($product_id), $attributes['description']);
// replace %%sitename%% with the site name
$attributes['title'] = str_replace('%%sitename%%', get_bloginfo('name'), $attributes['title']);
@Auke1810
Auke1810 / wppfm_exclude_product_ids_from_feed
Last active February 2, 2023 16:43
Removes specific products from the feed generation process
View wppfm_exclude_product_ids_from_feed
// woocommerce product feed manager (www.marketingrobot.com)
// Removes specific products ID's from the feed generation process
function wppfm_exclude_product_ids_from_feed( $products_queue, $feed_id ) {
$products_to_exclude = array(
'20872',
'20875',
'20876',
'20879',
'20883',
'20895',
@Auke1810
Auke1810 / shortcoder support
Created December 24, 2022 16:22
Woocommerce product feed manager snippet so the Shortcoder plugin is supported (https://wordpress.org/plugins/shortcoder/)
View shortcoder support
function wppfm_shortcoder_support( $attributes, $feed_id, $product_id ) {
if ( has_custom_field( $attributes['description'] ) ) {
$description = $attributes['description'];
$attr = [ 'name' => get_shortcode_name_from_description( $description ) ];
//parse shortcodes do_shortcode
$attributes['description'] = process_product_shortcode( $attr, $description, $product_id );
}
@Auke1810
Auke1810 / wppfm_product_category_string_gets_full_category_path.php
Last active September 28, 2022 12:56
If you want to override the Yoast default category to get the full category path of a product in the "product_type" attribute.
View wppfm_product_category_string_gets_full_category_path.php
<?php
function wppfm_product_category_string_gets_full_category_path( $data, $feed_id, $product_id ) {
$data['product_type'] = WPPFM_Taxonomies::get_shop_categories( $product_id, ' > ' );
// Always return data!
return $data;
}
@Auke1810
Auke1810 / alter-descr-item
Created August 25, 2022 06:36
Strip &nbsp; from description attributes in the woocommerce product feed manager from wpmarketingrobot.com
View alter-descr-item
<?php
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// Strip &nbsp; from description attributes
$attributes['description'] = str_replace('&nbsp;', ' ', $attributes['description']);
// IMPORTANT! Always return the $attributes
return $attributes;
}
@Auke1810
Auke1810 / gist:ba1f71311df86b19b580ff81c5216d25
Last active April 20, 2022 07:02
This is an example how to derive Taxonomy data from Wordpress and add this to the product feed created with the Woocommerce product feed manager from wpmarketingrobot.com You will need to edit the variabels in order to make it more readable for your taxonomy.
View gist:ba1f71311df86b19b580ff81c5216d25
/**
*
*/
function wppfm_add_taxonomy_data_to_feed( $data, $feed_id, $product_id ) {
// Get the product_badges taxonomy data.
$taxonomyName = 'product_taxonomy_data'; // use the name of your own taxonomy
$taxonomyData = wp_get_post_terms( $product_id, $taxonomyName );
if ( $taxonomyData ) {