id = 'sharethis'; $this->method_title = __( 'ShareThis', 'woocommerce' ); $this->method_description = __( 'ShareThis offers a sharing widget which will allow customers to share links to products with their friends.', 'woocommerce' ); $this->default_code = '
'; // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->publisher_id = $this->get_option( 'publisher_id' ); $this->sharethis_code = $this->get_option( 'sharethis_code', $this->default_code ); // Actions add_action( 'woocommerce_update_options_integration_sharethis', array( $this, 'process_admin_options' ) ); // Share widget add_action( 'woocommerce_share', array( $this, 'sharethis_code' ) ); } /** * Initialise Settings Form Fields * * @access public * @return void */ function init_form_fields() { $this->form_fields = array( 'publisher_id' => array( 'title' => __( 'ShareThis Publisher ID', 'woocommerce' ), 'description' => sprintf( __( 'Enter your %1$sShareThis publisher ID%2$s to show social sharing buttons on product pages.', 'woocommerce' ), '', '' ), 'type' => 'text', 'default' => get_option('woocommerce_sharethis') ), 'sharethis_code' => array( 'title' => __( 'ShareThis Code', 'woocommerce' ), 'description' => __( 'You can tweak the ShareThis code by editing this option.', 'woocommerce' ), 'type' => 'textarea', 'default' => $this->default_code ) ); } /** * Output share code. * * @access public * @return void */ function sharethis_code() { global $post; if ( $this->publisher_id ) { $thumbnail = ( $thumbnail_id = get_post_thumbnail_id( $post->ID ) ) ? current(wp_get_attachment_image_src( $thumbnail_id, 'large' )) : ''; $sharethis = ( is_ssl() ) ? 'https://ws.sharethis.com/button/buttons.js' : 'http://w.sharethis.com/button/buttons.js'; $sharethis_code = str_replace( '{permalink}', urlencode( get_permalink( $post->ID ) ), $this->sharethis_code ); if ( isset( $thumbnail ) ) $sharethis_code = str_replace( '{image}', urlencode( $thumbnail ), $sharethis_code ); echo str_replace( '&', '&', $sharethis_code ); echo ''; echo ''; } } } /** * Add the integration to WooCommerce. * * @package WooCommerce/Classes/Integrations * @access public * @param array $integrations * @return array */ function add_sharethis_integration( $integrations ) { $integrations[] = 'WC_ShareThis'; return $integrations; } add_filter('woocommerce_integrations', 'add_sharethis_integration' );