Last active
April 26, 2020 11:28
-
-
Save hxii/3b89e02cda136fc136c9a03ffd57035f to your computer and use it in GitHub Desktop.
Link bottomline shortcode to product page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function yotpo_bottomline( $args ) { | |
if ( ! class_exists( 'YRFW_API_Wrapper' ) ) { | |
require_once YRFW_PLUGIN_PATH . 'inc/Helpers/class-yrfw-api-wrapper.php'; | |
} | |
if ( ! array_key_exists( 'settings_instance', $GLOBALS ) ) { | |
$settings_instance = ( YRFW_Settings_File::get_instance() )->get_settings(); | |
} else { | |
global $settings_instance; | |
} | |
if ( isset( $args['product_id'] ) ) { | |
$product_id = $args['product_id']; | |
} elseif ( is_product() ) { | |
global $product; | |
$product_id = $product->get_id(); | |
} else { | |
return; | |
} | |
$curl = YRFW_API_Wrapper::get_instance(); | |
$curl->init( $settings_instance['app_key'], $settings_instance['secret'] ); | |
$response = json_decode( $curl->get_product_bottomline( $product_id ) ); | |
$html = ''; | |
if ( ! empty( $response ) ) { | |
if ( 200 === $response->status->code && $response->response->bottomline->total_reviews > 0 ) { | |
$product_handler = YRFW_Product_Cache::get_instance(); | |
$widget_product_data = $product_handler->get_cached_product( $product_id ); | |
$html = "<div class='yotpo bottomLine' | |
data-product-id='{$product_id}' | |
data-url='{$widget_product_data['url']}' | |
data-lang='{$widget_product_data['lang']}'> | |
</div>"; | |
if ( is_category() || is_archive() ) { | |
$html = "<a href='{$widget_product_data['url']}'>{$html}</a>"; | |
} | |
} elseif ( ! isset( $args['0'] ) || 'noempty' !== $args['0'] ) { | |
return $this->show_empty_bottomline(); | |
} else { | |
return; | |
} | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment