Skip to content

Instantly share code, notes, and snippets.

View koen12344's full-sized avatar

Koen koen12344

View GitHub Profile
@koen12344
koen12344 / pgbm_woocommerce_variation_price_variables.php
Created June 8, 2022 13:53
Add price variables for WooCommerce variations
<?php
//Remove the <?php opening tag to get rid of the red exclamation mark in the Code Snippets plugin
if(interface_exists('\PGMB\Placeholders\VariableInterface')){
class PGMB_WC_Variation_Prices implements \PGMB\Placeholders\VariableInterface{
private $product;
public function __construct($parent_id) {
@koen12344
koen12344 / hide_user_locations.php
Last active June 29, 2022 08:17
Hide specific locations from users in Post to GMB plugin
<?php
/*
It is possible to limit the location list to specific locations (or a single location) using the mbp_business_selector_locations filter.
We can use it to filter out the locations that don't belong to the website or user.
The code loops through all locations and checks whether the location is within an array of allowed locations. If not, it is removed (hidden).
You can find the location ID by right clicking the location in the location selector, and pressing "Inspect Element": https://i.imgur.com/gWd5M9x.png
<?php
function pgmb_add_event_fields( $variables, $parent_post_id ) {
$event_start_date = get_post_meta( $parent_post_id, 'WooCommerceEventsDateTimestamp', true );
$event_end_date = get_post_meta( $parent_post_id, 'WooCommerceEventsEndDateTimestamp', true );
if ( ! $event_start_date || !$event_end_date ) {
return $variables;
}
$start_datetime = new \DateTime();
@koen12344
koen12344 / bulk-update-auto-post-template.php
Created July 15, 2022 13:20
Snippet to bulk change the auto-post template for a selection of posts
<?php
function pgmb_batch_update_templates(){
$product_ids = get_posts([
'post_type' => 'product',
'fields' => 'ids',
'numberposts' => '-1',
]);
foreach($product_ids as $product_id){
$product = wc_get_product($product_id);
<?php
function pgmb_add_calendarize_it_fields( $variables, $parent_post_id ) {
$event_start_date = get_post_meta( $parent_post_id, 'fc_start_datetime', true );
$event_end_date = get_post_meta( $parent_post_id, 'fc_end_datetime', true );
if ( ! $event_start_date || !$event_end_date ) {
return $variables;
}
$start_datetime = new \DateTime($event_start_date);
@koen12344
koen12344 / pgmb_business_selector_full_height.php
Created September 22, 2022 08:19
Force the business selector to be 100% height
<?php
add_action('admin_head', 'pgmb_increase_height');
function pgmb_increase_height() {
echo '<style>
.mbp-business-selector {
height:100% !important;
}
</style>';
}
<?php
function pgmb_add_custom_variable($variables, $parent_post_id){
$variables['%custom_variable%'] = get_post_meta($parent_post_id, 'custom_variable', true);
return $variables;
}
add_filter('mbp_placeholder_variables', 'pgmb_add_custom_variable', 10, 2);
@koen12344
koen12344 / pgmb_add_yoast_description.php
Created October 18, 2022 11:24
Add yoast seo description to post to GMB plugin
<?php
function pgmb_add_yoast_description($variables, $parent_post_id){
if(!function_exists('YoastSEO')){ return $variables; }
$description = YoastSEO()->meta->for_post( $parent_post_id )->description;
$variables['%yoast_description%'] = $description;
return $variables;
}
add_filter( 'mbp_placeholder_variables', 'pgmb_add_yoast_description', 10, 2 );
<?php
function pgmb_publish_all_products(){
if(get_option('pgmb_products_synced')){
return;
}
global $post_to_google_my_business;
if(!$post_to_google_my_business->is_loaded()){
return;
}
wc_product_price: %wc_product_price%
wc_product_regular_price: %wc_product_regular_price%
wc_product_sale_price: %wc_product_sale_price%
wc_product_price_including_tax: %wc_product_price_including_tax%
wc_currency_symbol: %wc_currency_symbol% (do not use this in the price field!)
wc_variation_min_current_price: %wc_variation_min_current_price%
wc_variation_max_current_price: %wc_variation_max_current_price%
wc_variation_min_regular_price: %wc_variation_min_regular_price%
wc_variation_max_regular_price: %wc_variation_max_regular_price%
wc_variation_min_sale_price: %wc_variation_min_sale_price%