WordPress.org

Support

Support » Plugins and Hacks » Code in improved_external_prod.php overriding hooks

Code in improved_external_prod.php overriding hooks

  • datafeedr
    Participant

    @datafeedrcom

    Hi,

    Your plugin is very useful & simple. However there’s a problem in your improved_external_prod.php file. Because you are getting the “_product_url” and “_button_text” directly from the postmeta table using get_post_meta(), you are bypassing any filters that might get applied to that data.

    May I suggest changing this:

    function woocommerce_external_add_to_cart() {
    		global $product;
    
    		$product_url = get_post_meta( $product->id, '_product_url', true  );
    		$button_text = get_post_meta( $product->id, '_button_text', true  );
    
    		if ( ! $product_url ) return;
    
    		woocommerce_get_template( '../../woocommerce-improved-external-products/external.php', array(
    				'product_url' => $product_url,
    				'button_text' => ( $button_text ) ? $button_text : __( 'Buy product', 'woocommerce' ) ,
    			) );
    	}

    To this:

    function woocommerce_external_add_to_cart() {
    		global $product;
    
    		if ( ! $product->get_product_url() )
    			return;
    
    		woocommerce_get_template( '../../woocommerce-improved-external-products/external.php', array(
    				'product_url' => $product->get_product_url(),
    				'button_text' => $product->single_add_to_cart_text()
    			) );
    	}

    This will still allow your plugin to call your custom external.php file for adding the target=”_blank” code however it won’t bypass any WC hooks being applied to the product URL or button text.

    Thanks,
    Eric

    http://wordpress.org/plugins/woocommerce-improved-external-products/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jeremiah
    Participant

    @jprummer

    Thanks for the suggestion! I’ll see if I can push this out in the next week or so. The plugin is definitely due for an update as it’s been quite awhile…

    datafeedr
    Participant

    @datafeedrcom

    Thanks for the quick reply! That would be fantastic.

    Eric

    viewridge
    Member

    @viewridge

    Hello, I was curious if you’ve made any progress in making the changes to your plugin as discussed above. Thanks for your time.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code in improved_external_prod.php overriding hooks’ is closed to new replies.